/* * 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 . */ const XMLUtils = require('pydio/util/xml') const InputBoolean = require('./../fields/InputBoolean') const InputText = require('./../fields/TextField') const ValidPassword = require('./../fields/ValidPassword') const InputInteger = require('./../fields/InputInteger') const InputButton = require('./../fields/InputButton') const MonitoringLabel = require('./../fields/MonitoringLabel') const InputImage = require('./../fields/InputImage') const SelectBox = require('./../fields/InputSelectBox') const AutocompleteBox = require('./../fields/AutocompleteBox') /** * Utility class to parse / handle pydio standard form definitions/values. */ export default class Manager{ static hasHelper(pluginId, paramName){ const helpers = Manager.getHelpersCache(); return (helpers[pluginId] && helpers[pluginId]['parameters'][paramName]); } static getHelpersCache(){ if(!Manager.HELPERS_CACHE){ var helperCache = {}; var helpers = XMLUtils.XPathSelectNodes(window.pydio.Registry.getXML(), 'plugins/*/client_settings/resources/js[@type="helper"]'); for(var i = 0; i; break; case 'string': case 'textarea': case 'password': value = ; break; case 'valid-password': value = ; break; case 'integer': value = ; break; case 'button': value = ; break; case 'monitor': value = ; break; case 'image': value = ; break; case 'select': value = ; break; case 'autocomplete': value = ; break; case 'legend': value = null; break; case 'hidden': value = null; break; default: if(!props.value){ value = Empty; }else{ value = props.value; } break; } return value; } /** * * Extract POST-ready values from a combo parameters/values * * @param definitions Array Standard Form Definition array * @param values Object Key/Values of the current form * @param prefix String Optional prefix to add to all parameters (by default DRIVER_OPTION_). * @returns Object Object with all pydio-compatible POST parameters */ static getValuesForPOST(definitions, values, prefix='DRIVER_OPTION_', additionalMetadata=null){ var clientParams = {}; for(var key in values){ if(values.hasOwnProperty(key)) { clientParams[prefix+key] = values[key]; var defType = null; for(var d = 0; d 1) { last = parts.pop(); prev = parts.pop(); } for(var k = 0; k 0){ if(!parentKey){ parentKey = treeKeys; } if(!parentKey[parentName]) { parentKey[parentName] = {}; } parentKey = parentKey[parentName]; parentName = parts.shift(); } var type = clientParams[typeKey]; delete clientParams[typeKey]; if(parentKey && !parentKey[parentName]) { if(type == "boolean"){ var v = clientParams[key]; parentKey[parentName] = (v == "true" || v == 1 || v === true ); }else if(type == "integer") { parentKey[parentName] = parseInt(clientParams[key]); }else if(type && type.startsWith("group_switch:") && typeof clientParams[key] == "string"){ parentKey[parentName] = {group_switch_value:clientParams[key]}; }else{ parentKey[parentName] = clientParams[key]; } }else if(parentKey && type && type.startsWith('group_switch:')){ parentKey[parentName]["group_switch_value"] = clientParams[key]; } delete clientParams[key]; }); for(key in treeKeys){ if(!treeKeys.hasOwnProperty(key)) continue; var treeValue = treeKeys[key]; if(clientParams[key + '_ajxptype'] && clientParams[key + '_ajxptype'].indexOf('group_switch:') === 0 && !treeValue['group_switch_value']){ treeValue['group_switch_value'] = clientParams[key]; } clientParams[key] = JSON.stringify(treeValue); clientParams[key+'_ajxptype'] = "text/json"; } // Clean XXX_group_switch parameters for(var theKey in clientParams){ if(!clientParams.hasOwnProperty(theKey)) continue; if(theKey.indexOf("/") == -1 && clientParams[theKey] && clientParams[theKey + "_ajxptype"] && clientParams[theKey + "_ajxptype"].startsWith("group_switch:")){ if(typeof clientParams[theKey] == "string"){ clientParams[theKey] = JSON.stringify({group_switch_value:clientParams[theKey]}); clientParams[theKey + "_ajxptype"] = "text/json"; } } if(clientParams.hasOwnProperty(theKey)){ if(theKey.endsWith("_group_switch")){ delete clientParams[theKey]; } } } return clientParams; } }