/*
* Copyright 2015 Anyware Services
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* DAO for manipulating a skin
*/
Ext.define("Ametys.plugins.web.skin.SkinDAO",
{
singleton: true,
constructor: function ()
{
/**
* @callable
* @member Ametys.plugins.web.skin.SkinDAO
* @method getSkin
* This calls the method 'getSkin' of the server DAO 'org.ametys.web.skin.SkinDAO'.
* Retrieve the informations on a specific skin.
* @param {Object[]} parameters The parameters to transmit to the server method.
* @param {String} parameters.skinId The id of the skin
* @param {Function} callback The function to call when the java process is over. Use options.scope for the scope.
* @param {Object} callback.returnedValue The value return from the server (please note that when an error occured, the callback may not be called depending on the value of errorMessage).
* @param {String} callback.returnedValue.id The id of the skin
* @param {String} callback.returnedValue.label The label of the skin
* @param {Boolean} callback.returnedValue.inUse If the skin is used by at least one site.
* @param {Object} callback.returnedValue.model The name of the model of the skin. Can be null
* @param {Object} callback.arguments Other arguments specified in option.arguments
* @param {Object} [options] Advanced options for the call.
* @param {Boolean/String/Object} [options.errorMessage] Display an error message. See Ametys.data.ServerComm#callMethod errorMessage.
* @param {Boolean/String/Object} [options.waitMessage] Display a waiting message. See Ametys.data.ServerComm#callMethod waitMessage.
* @param {Number} [options.scope] This parameter is the scope used to call the callback. Moreover is the given class is a mixin of Ametys.data.ServerCaller, its methods Ametys.data.ServerCaller#beforeServerCall and Ametys.data.ServerCaller#afterServerCall will be used so see their documentation to look for additional options (such a refreshing on Ametys.ribbon.element.ui.ButtonController#beforeServerCall).
* @param {Number} [options.priority] The message priority. See Ametys.data.ServerComm#callMethod for more information on the priority. PRIORITY_SYNCHRONOUS cannot be used here.
* @param {String} [options.cancelCode] Cancel similar unachieved read operations. See Ametys.data.ServerComm#callMethod cancelCode.
* @param {Object} [options.arguments] Additional arguments set in the callback.arguments parameter.
* @param {Boolean} [options.ignoreCallbackOnError] If the server throws an exception, should the callback beeing called with a null parameter. See Ametys.data.ServerComm#callMethod ignoreOnError.
*/
this.addCallables(
{
role: "org.ametys.web.skin.SkinDAO",
methodName: "getSkin",
waitMessage: false,
errorMessage: {
msg: "{{i18n PLUGINS_WEB_ADMINISTRATOR_GET_SKIN_ERROR}}",
category: Ext.getClassName(this)
}
});
/**
* @callable
* @member Ametys.plugins.web.skin.SkinDAO
* @method getSkins
* This calls the method 'getSkins' of the server DAO 'org.ametys.web.skin.SkinDAO'.
* Retrieve the list of skins from the server.
* @param {Object[]} parameters The parameters to transmit to the server method. Should be an empty array because this method require.
* @param {Boolean} parameters.includeAbstract True to also includes abstract skins
* @param {Function} callback The function to call when the java process is over. Use options.scope for the scope.
* @param {Object} callback.returnedValue The value return from the server. Null on error (please note that when an error occured, the callback may not be called depending on the value of errorMessage).
* @param {Object[]} callback.returnedValue.models The list of models availables
* @param {Object[]} callback.returnedValue.skins The list of skins availables
* @param {Object} callback.arguments Other arguments specified in option.arguments
* @param {Object} [options] Advanced options for the call.
* @param {Boolean/String/Object} [options.errorMessage] Display an error message. See Ametys.data.ServerComm#callMethod errorMessage.
* @param {Boolean/String/Object} [options.waitMessage] Display a waiting message. See Ametys.data.ServerComm#callMethod waitMessage.
* @param {Number} [options.scope] This parameter is the scope used to call the callback. Moreover is the given class is a mixin of Ametys.data.ServerCaller, its methods Ametys.data.ServerCaller#beforeServerCall and Ametys.data.ServerCaller#afterServerCall will be used so see their documentation to look for additional options (such a refreshing on Ametys.ribbon.element.ui.ButtonController#beforeServerCall).
* @param {Number} [options.priority] The message priority. See Ametys.data.ServerComm#callMethod for more information on the priority. PRIORITY_SYNCHRONOUS cannot be used here.
* @param {String} [options.cancelCode] Cancel similar unachieved read operations. See Ametys.data.ServerComm#callMethod cancelCode.
* @param {Object} [options.arguments] Additional arguments set in the callback.arguments parameter.
* @param {Boolean} [options.ignoreCallbackOnError] If the server throws an exception, should the callback beeing called with a null parameter. See Ametys.data.ServerComm#callMethod ignoreOnError.
*/
this.addCallables(
{
role: "org.ametys.web.skin.SkinDAO",
methodName: "getSkins",
waitMessage: true,
errorMessage: {
msg: "{{i18n PLUGINS_WEB_ADMINISTRATOR_GET_SKINS_ERROR}}",
category: Ext.getClassName(this)
}
});
/**
* @callable
* @member Ametys.plugins.web.skin.SkinDAO
* @method importSkin
* This calls the method 'importSkin' of the server DAO 'org.ametys.web.skin.SkinDAO'.
* Import a skin that was previously uploaded on the server
* @param {Object[]} parameters The parameters to transmit to the server method.
* @param {String} parameters.skinName The name of the new skin
* @param {String} parameters.tmpDirPath The temporary directory path where the skin was uploaded
* @param {Object} parameters.values The configuration's values.
* @param {Function} callback The function to call when the java process is over. Use options.scope for the scope.
* @param {String} callback.returnedValue The name of the skin. (please note that when an error occured, the callback may not be called depending on the value of errorMessage).
* @param {Object} callback.arguments Other arguments specified in option.arguments
* @param {Object} [options] Advanced options for the call.
* @param {Boolean/String/Object} [options.errorMessage] Display an error message. See Ametys.data.ServerComm#callMethod errorMessage.
* @param {Boolean/String/Object} [options.waitMessage] Display a waiting message. See Ametys.data.ServerComm#callMethod waitMessage.
* @param {Number} [options.scope] This parameter is the scope used to call the callback. Moreover is the given class is a mixin of Ametys.data.ServerCaller, its methods Ametys.data.ServerCaller#beforeServerCall and Ametys.data.ServerCaller#afterServerCall will be used so see their documentation to look for additional options (such a refreshing on Ametys.ribbon.element.ui.ButtonController#beforeServerCall).
* @param {Number} [options.priority] The message priority. See Ametys.data.ServerComm#callMethod for more information on the priority. PRIORITY_SYNCHRONOUS cannot be used here.
* @param {String} [options.cancelCode] Cancel similar unachieved read operations. See Ametys.data.ServerComm#callMethod cancelCode.
* @param {Object} [options.arguments] Additional arguments set in the callback.arguments parameter.
* @param {Boolean} [options.ignoreCallbackOnError] If the server throws an exception, should the callback beeing called with a null parameter. See Ametys.data.ServerComm#callMethod ignoreOnError.
*/
this.addCallables(
{
role: "org.ametys.web.skin.SkinDAO",
methodName: "importSkin",
callback: {
handler: this._importSkinCb
},
localParamsIndex: 3,
waitMessage: true,
errorMessage: {
msg: "{{i18n PLUGINS_WEB_ADMINISTRATOR_SKINS_HANDLE_IMPORT_ERROR}}",
category: Ext.getClassName(this)
}
});
/**
* @callable
* @member Ametys.plugins.web.skin.SkinDAO
* @method configureSkin
* This calls the method 'configureSkin' of the server DAO 'org.ametys.web.skin.SkinDAO'.
* Configure a skin
* @param {Object[]} parameters The parameters to transmit to the server method.
* @param {String} parameters.skinName The name of the skin
* @param {Object} parameters.values The configuration's values.
* @param {Ametys.form.ConfigurableFormPanel} parameters.form The form configuration
* @param {Function} callback The function to call when the java process is over. Use options.scope for the scope.
* @param {String} callback.returnedValue The name of the skin. (please note that when an error occured, the callback may not be called depending on the value of errorMessage).
* @param {Object} callback.arguments Other arguments specified in option.arguments
* @param {Object} [options] Advanced options for the call.
* @param {Boolean/String/Object} [options.errorMessage] Display an error message. See Ametys.data.ServerComm#callMethod errorMessage.
* @param {Boolean/String/Object} [options.waitMessage] Display a waiting message. See Ametys.data.ServerComm#callMethod waitMessage.
* @param {Number} [options.scope] This parameter is the scope used to call the callback. Moreover is the given class is a mixin of Ametys.data.ServerCaller, its methods Ametys.data.ServerCaller#beforeServerCall and Ametys.data.ServerCaller#afterServerCall will be used so see their documentation to look for additional options (such a refreshing on Ametys.ribbon.element.ui.ButtonController#beforeServerCall).
* @param {Number} [options.priority] The message priority. See Ametys.data.ServerComm#callMethod for more information on the priority. PRIORITY_SYNCHRONOUS cannot be used here.
* @param {String} [options.cancelCode] Cancel similar unachieved read operations. See Ametys.data.ServerComm#callMethod cancelCode.
* @param {Object} [options.arguments] Additional arguments set in the callback.arguments parameter.
* @param {Boolean} [options.ignoreCallbackOnError] If the server throws an exception, should the callback beeing called with a null parameter. See Ametys.data.ServerComm#callMethod ignoreOnError.
*/
this.addCallables(
{
role: "org.ametys.web.skin.SkinDAO",
methodName: "configureSkin",
localParamsIndex: 2,
callback: {
handler: this._configureSkinCb
},
errorMessage: {
category: Ext.getClassName(this),
msg: "{{i18n PLUGINS_WEB_ADMINISTRATOR_SKINS_SAVE_CONFIG_ERROR}}"
},
waitMessage: {
msg: "{{i18n PLUGINS_WEB_ADMINISTRATOR_SKINS_SAVING}}"
}
});
/**
* @callable
* @member Ametys.plugins.web.skin.SkinDAO
* @method copySkin
* This calls the method 'copySkin' of the server DAO 'org.ametys.web.skin.SkinDAO'.
* Copy an existing skin into a new skin
* @param {Object[]} parameters The parameters to transmit to the server method.
* @param {String} parameters.skinId The id of the new skin
* @param {String} parameters.originalSkinId The id of the existing skin used for duplication
* @param {Function} callback The function to call when the java process is over. Use options.scope for the scope.
* @param {String} callback.returnedValue An error message. Null on success.(please note that when an error occured, the callback may not be called depending on the value of errorMessage).
* @param {Object} callback.arguments Other arguments specified in option.arguments
* @param {Object} [options] Advanced options for the call.
* @param {Boolean/String/Object} [options.errorMessage] Display an error message. See Ametys.data.ServerComm#callMethod errorMessage.
* @param {Boolean/String/Object} [options.waitMessage] Display a waiting message. See Ametys.data.ServerComm#callMethod waitMessage.
* @param {Number} [options.scope] This parameter is the scope used to call the callback. Moreover is the given class is a mixin of Ametys.data.ServerCaller, its methods Ametys.data.ServerCaller#beforeServerCall and Ametys.data.ServerCaller#afterServerCall will be used so see their documentation to look for additional options (such a refreshing on Ametys.ribbon.element.ui.ButtonController#beforeServerCall).
* @param {Number} [options.priority] The message priority. See Ametys.data.ServerComm#callMethod for more information on the priority. PRIORITY_SYNCHRONOUS cannot be used here.
* @param {String} [options.cancelCode] Cancel similar unachieved read operations. See Ametys.data.ServerComm#callMethod cancelCode.
* @param {Object} [options.arguments] Additional arguments set in the callback.arguments parameter.
* @param {Boolean} [options.ignoreCallbackOnError] If the server throws an exception, should the callback beeing called with a null parameter. See Ametys.data.ServerComm#callMethod ignoreOnError.
*/
this.addCallables(
{
role: "org.ametys.web.skin.SkinDAO",
methodName: "copySkin",
callback: {
handler: this._copySkinCb
},
waitMessage: {
msg: "{{i18n PLUGINS_WEB_ADMINISTRATOR_SKINS_HANDLE_COPY_RUNNING}}",
category: Ext.getClassName(this)
},
errorMessage: {
msg: "{{i18n PLUGINS_WEB_ADMINISTRATOR_SKINS_HANDLE_COPY_ERROR}}",
category: Ext.getClassName(this)
}
});
/**
* @callable
* @member Ametys.plugins.web.skin.SkinDAO
* @method deleteSkin
* This calls the method 'deleteSkin' of the server DAO 'org.ametys.web.skin.SkinDAO'.
* Delete a skin
* @param {Object[]} parameters The parameters to transmit to the server method.
* @param {String} parameters.id The id of the skin
* @param {Ametys.message.MessageTarget} parameters.target The skin target
* @param {Function} callback The function to call when the java process is over. Use options.scope for the scope.
* @param {String} callback.returnedValue The name of the skin. (please note that when an error occured, the callback may not be called depending on the value of errorMessage).
* @param {Object} callback.arguments Other arguments specified in option.arguments
* @param {Object} [options] Advanced options for the call.
* @param {Boolean/String/Object} [options.errorMessage] Display an error message. See Ametys.data.ServerComm#callMethod errorMessage.
* @param {Boolean/String/Object} [options.waitMessage] Display a waiting message. See Ametys.data.ServerComm#callMethod waitMessage.
* @param {Number} [options.scope] This parameter is the scope used to call the callback. Moreover is the given class is a mixin of Ametys.data.ServerCaller, its methods Ametys.data.ServerCaller#beforeServerCall and Ametys.data.ServerCaller#afterServerCall will be used so see their documentation to look for additional options (such a refreshing on Ametys.ribbon.element.ui.ButtonController#beforeServerCall).
* @param {Number} [options.priority] The message priority. See Ametys.data.ServerComm#callMethod for more information on the priority. PRIORITY_SYNCHRONOUS cannot be used here.
* @param {String} [options.cancelCode] Cancel similar unachieved read operations. See Ametys.data.ServerComm#callMethod cancelCode.
* @param {Object} [options.arguments] Additional arguments set in the callback.arguments parameter.
* @param {Boolean} [options.ignoreCallbackOnError] If the server throws an exception, should the callback beeing called with a null parameter. See Ametys.data.ServerComm#callMethod ignoreOnError.
*/
this.addCallables(
{
role: "org.ametys.web.skin.SkinDAO",
methodName: "deleteSkin",
localParamsIndex: 1,
callback: {
handler: this._deleteSkinCb
},
waitMessage: true,
errorMessage: {
msg: "{{i18n PLUGINS_WEB_ADMINISTRATOR_SKINS_HANDLE_DELETE_ERROR}}",
category: Ext.getClassName(this)
}
});
/**
* @callable
* @member Ametys.plugins.web.skin.SkinDAO
* @method skinExists
* This calls the method 'skinExists' of the server DAO 'org.ametys.web.skin.SkinDAO'.
* Determines if a skin exists.
* @param {Object[]} parameters The parameters to transmit to the server method.
* @param {String} parameters.id The id of the skin
* @param {Function} callback The function to call when the java process is over. Use options.scope for the scope.
* @param {Boolean} callback.exists True if the skin exists, false otherwise.
* @param {Object} callback.arguments Other arguments specified in option.arguments
* @param {Object} [options] Advanced options for the call.
* @param {Boolean/String/Object} [options.errorMessage] Display an error message. See Ametys.data.ServerComm#callMethod errorMessage.
* @param {Boolean/String/Object} [options.waitMessage] Display a waiting message. See Ametys.data.ServerComm#callMethod waitMessage.
* @param {Number} [options.scope] This parameter is the scope used to call the callback. Moreover is the given class is a mixin of Ametys.data.ServerCaller, its methods Ametys.data.ServerCaller#beforeServerCall and Ametys.data.ServerCaller#afterServerCall will be used so see their documentation to look for additional options (such a refreshing on Ametys.ribbon.element.ui.ButtonController#beforeServerCall).
* @param {Number} [options.priority] The message priority. See Ametys.data.ServerComm#callMethod for more information on the priority. PRIORITY_SYNCHRONOUS cannot be used here.
* @param {String} [options.cancelCode] Cancel similar unachieved read operations. See Ametys.data.ServerComm#callMethod cancelCode.
* @param {Object} [options.arguments] Additional arguments set in the callback.arguments parameter.
* @param {Boolean} [options.ignoreCallbackOnError] If the server throws an exception, should the callback beeing called with a null parameter. See Ametys.data.ServerComm#callMethod ignoreOnError.
*/
this.addCallables(
{
role: "org.ametys.web.skin.SkinDAO",
methodName: "skinExists",
errorMessage: true
});
/**
* @callable
* @member Ametys.plugins.web.skin.SkinDAO
* @method isInUse
* This calls the method 'isInUse' of the server DAO 'org.ametys.web.skin.SkinDAO'.
* Determines if a skin is currently used by one or more skins.
* @param {Object[]} parameters The parameters to transmit to the server method.
* @param {String} parameters.id The id of the skin
* @param {Function} callback The function to call when the java process is over. Use options.scope for the scope.
* @param {Boolean} callback.inUse True if the skin is in use
* @param {Object} callback.arguments Other arguments specified in option.arguments
* @param {Object} [options] Advanced options for the call.
* @param {Boolean/String/Object} [options.errorMessage] Display an error message. See Ametys.data.ServerComm#callMethod errorMessage.
* @param {Boolean/String/Object} [options.waitMessage] Display a waiting message. See Ametys.data.ServerComm#callMethod waitMessage.
* @param {Number} [options.scope] This parameter is the scope used to call the callback. Moreover is the given class is a mixin of Ametys.data.ServerCaller, its methods Ametys.data.ServerCaller#beforeServerCall and Ametys.data.ServerCaller#afterServerCall will be used so see their documentation to look for additional options (such a refreshing on Ametys.ribbon.element.ui.ButtonController#beforeServerCall).
* @param {Number} [options.priority] The message priority. See Ametys.data.ServerComm#callMethod for more information on the priority. PRIORITY_SYNCHRONOUS cannot be used here.
* @param {String} [options.cancelCode] Cancel similar unachieved read operations. See Ametys.data.ServerComm#callMethod cancelCode.
* @param {Object} [options.arguments] Additional arguments set in the callback.arguments parameter.
* @param {Boolean} [options.ignoreCallbackOnError] If the server throws an exception, should the callback beeing called with a null parameter. See Ametys.data.ServerComm#callMethod ignoreOnError.
*/
this.addCallables(
{
role: "org.ametys.web.skin.SkinDAO",
methodName: "isInUse",
errorMessage: "{{i18n PLUGINS_WEB_ADMINISTRATOR_SKINS_TEST_USED_ERROR}}"
});
},
/**
* Callback after importing a skin. Send a CREATE Message
* @param {Object} response The server result
* @param {Object} response.skinId The id of imported skin
* @param {Object[]} response.errors The configuration's error
* @param {Object} args The callback arguments
* @param {Object[]} params The callback parameters (server-side and client-side)
* @param {String} params.id The id of configured skin
* @param {Object} params.values The form's values
* @param {Ametys.form.ConfigurableFormPanel} params.form The form
* @private
*/
_importSkinCb: function (response, args, params)
{
var form = params[3];
var fieldsInError = {};
// Handle form errors
var errors = response.errors || [];
if (errors.length > 0)
{
for (var i=0; i < errors.length; i++)
{
var fdName = errors[i].name;
var errorMsg = errors[i].errorMessages.join("<br/>");
fieldsInError[fdName] = errorMsg;
}
}
if (errors.length > 0 && form)
{
var msg = "{{i18n PLUGINS_WEB_ADMINISTRATOR_SKINS_SAVE_CONFIG_FAILED_DESC}}";
msg += errors.length == 1 ? "{{i18n PLUGINS_WEB_ADMINISTRATOR_SKINS_SAVE_CONFIG_FAILED_DESC_SINGLE}}" : errors.length + "{{i18n PLUGINS_WEB_ADMINISTRATOR_SKINS_SAVE_CONFIG_FAILED_DESC_MULTI}}";
Ametys.form.SaveHelper.handleServerErrors(form, null, msg, fieldErrors);
return;
}
Ext.create("Ametys.message.Message",
{
type: Ametys.message.Message.CREATED,
targets:
{
id: Ametys.message.MessageTarget.SKIN,
parameters:
{
id: response.skinId
}
}
});
},
/**
* @private
* Callback function called after configuring skin
* @param {Object} response The server result
* @param {Object} args The callback arguments
* @param {Object[]} params The callback parameters (server-side and client-side)
* @param {String} params.id The id of configured skin
* @param {Object} params.values The form's values
* @param {Ametys.form.ConfigurableFormPanel} params.form The form
*/
_configureSkinCb: function (response, args, params)
{
var form = params[2];
var fieldsInError = {};
// Handle form errors
var errors = response.errors || [];
if (errors.length > 0)
{
for (var i=0; i < errors.length; i++)
{
var fdName = errors[i].name;
var errorMsg = errors[i].errorMessages.join("<br/>");
fieldsInError[fdName] = errorMsg;
}
}
if (errors.length > 0 && form)
{
var msg = "{{i18n PLUGINS_WEB_ADMINISTRATOR_SKINS_SAVE_CONFIG_FAILED_DESC}}";
msg += errors.length == 1 ? "{{i18n PLUGINS_WEB_ADMINISTRATOR_SKINS_SAVE_CONFIG_FAILED_DESC_SINGLE}}" : errors.length + "{{i18n PLUGINS_WEB_ADMINISTRATOR_SKINS_SAVE_CONFIG_FAILED_DESC_MULTI}}";
Ametys.form.SaveHelper.handleServerErrors(form, null, msg, fieldErrors);
return;
}
Ext.create('Ametys.message.Message', {
type: Ametys.message.Message.MODIFIED,
targets: [{
id: Ametys.message.MessageTarget.SKIN,
parameters: {
id: params[0]
}
}]
});
},
/**
* Callback after copying a skin. Send a CREATE Message
* @param {String} error An error code, or null on success
* @param {Object} args The callback arguments
* @param {String[]} params The parameters
* @private
*/
_copySkinCb: function (error, args, params)
{
if (error && error == "already-exists")
{
Ametys.Msg.show({
title: "{{i18n PLUGINS_WEB_ADMINISTRATOR_SKINS_ALREADY_EXIST_TITLE}}",
msg: "{{i18n PLUGINS_WEB_ADMINISTRATOR_SKINS_ALREADY_EXIST}}",
buttons: Ext.Msg.OK,
icon: Ext.MessageBox.ERROR
});
}
else if (!error)
{
var skinId = params[0];
Ext.create("Ametys.message.Message",
{
type: Ametys.message.Message.CREATED,
targets:
{
id: Ametys.message.MessageTarget.SKIN,
parameters:
{
id: skinId
}
}
});
}
},
/**
* Callback after deleting a skin. Send a DELETE Message
* @param {String} skinId The id of the skin
* @param {Object} args The callback arguments
* @param {String[]} params The parameters
* @private
*/
_deleteSkinCb: function (skinId, args, params)
{
Ext.create("Ametys.message.Message",
{
type: Ametys.message.Message.DELETED,
targets: params[1]
});
}
});