/* * Copyright 2007-2017 Charles du Jeu - Abstrium SAS * This file is part of Pydio. * * Pydio is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Pydio is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with Pydio. If not, see . * * The latest code can be found at . */ import FormMixin from '../mixins/FormMixin' const React = require('react') const {SelectField, MenuItem, Chip} = require('material-ui') const LangUtils = require('pydio/util/lang') import FieldWithChoices from '../mixins/FieldWithChoices' /** * Select box input conforming to Pydio standard form parameter. */ let InputSelectBox = React.createClass({ mixins:[FormMixin], getDefaultProps:function(){ return { skipBufferChanges:true }; }, onDropDownChange:function(event, index, value){ this.onChange(event, value); this.toggleEditMode(); }, onMultipleSelect:function(event, index, newValue){ if(newValue == -1) return; const currentValue = this.state.value; let currentValues = (typeof currentValue === 'string' ? currentValue.split(',') : currentValue); if(!currentValues.indexOf(newValue) !== -1){ currentValues.push(newValue); this.onChange(event, currentValues.join(',')); } this.toggleEditMode(); }, onMultipleRemove: function(value){ const currentValue = this.state.value; let currentValues = (typeof currentValue === 'string' ? currentValue.split(',') : currentValue); if(currentValues.indexOf(value) !== -1 ){ currentValues = LangUtils.arrayWithout(currentValues, currentValues.indexOf(value)); this.onChange(null, currentValues.join(',')); } }, render:function(){ let currentValue = this.state.value; let menuItems = [], multipleOptions = [], mandatory = true; if(!this.props.attributes['mandatory'] || this.props.attributes['mandatory'] != "true"){ mandatory = false; menuItems.push(); } const {choices} = this.props; choices.forEach(function(value, key){ menuItems.push(); multipleOptions.push({value:key, label:value}); }); if((this.isDisplayGrid() && !this.state.editMode) || this.props.disabled){ let value = this.state.value; if(choices.get(value)) value = choices.get(value); return (
{!value?'Empty':value}   
); } else { let hasValue = false; if(this.props.multiple && this.props.multiple == true){ let currentValues = currentValue; if(typeof currentValue === "string"){ currentValues = currentValue.split(","); } hasValue = currentValues.length ? true: false; return (
{currentValues.map((v) => { return {this.onMultipleRemove(v)}}>{v}; })}
{menuItems}
); }else{ return( {menuItems} ); } } } }); InputSelectBox = FieldWithChoices(InputSelectBox); export {InputSelectBox as default}