123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- // Copyright (C) 2010-2016 Combodo SARL
- //
- // This file is part of iTop.
- //
- // iTop 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.
- //
- // iTop 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 iTop. If not, see <http://www.gnu.org/licenses/>
- //iTop Form handler
- ;
- $(function()
- {
- // the widget definition, where 'itop' is the namespace,
- // 'consoleform_handler' the widget name
- $.widget( 'itop.console_form_handler', $.itop.form_handler,
- {
- // default options
- options:
- {
- wizard_helper_var_name: '', // Name of the global variable pointing to the wizard helper
- custom_field_attcode: ''
- },
- // the constructor
- _create: function()
- {
- var me = this;
-
- this.element
- .addClass('console_form_handler');
- this.options.oWizardHelper = window[this.options.wizard_helper_var_name];
- this._super();
- },
-
- // events bound via _bind are removed automatically
- // revert other modifications here
- _destroy: function()
- {
- this.element
- .removeClass('console_form_handler');
- this._super();
- },
- _onUpdateFields: function(event, data)
- {
- var me = this;
- var sFormPath = data.form_path;
- var sUpdateUrl = GetAbsoluteUrlAppRoot()+'pages/ajax.render.php';
- $(this.element.find('[data-form-path="' + sFormPath + '"]')).block({message:''});
- $.post(
- sUpdateUrl,
- {
- operation: 'custom_fields_update',
- attcode: this.options.custom_field_attcode,
- //current_values: this.getCurrentValues(),
- requested_fields: data.requested_fields,
- form_path: sFormPath,
- json_obj: this.options.oWizardHelper.UpdateWizardToJSON()
- },
- function(data){
- me._onUpdateSuccess(data, sFormPath);
- }
- )
- .fail(function(data){ me._onUpdateFailure(data, sFormPath); })
- .always(function(data){
- me.alignColumns();
- $(me.element.find('[data-form-path="' + sFormPath + '"]')).unblock();
- me._onUpdateAlways(data, sFormPath);
- });
- },
- // On initialization or update
- alignColumns: function()
- {
- var iMaxWidth = 0;
- var oLabels = $(this.element.find('td.form-field-label'));
- // Reset the width to the automatic (original) value
- oLabels.width('');
- oLabels.each(function() {
- iMaxWidth = Math.max(iMaxWidth, $(this).width());
- });
- oLabels.width(iMaxWidth);
- },
- // Intended for overloading in derived classes
- _onSubmitClick: function()
- {
- },
- // Intended for overloading in derived classes
- _onCancelClick: function()
- {
- },
- // Intended for overloading in derived classes
- _onUpdateFailure: function(data)
- {
- },
- // Intended for overloading in derived classes
- _disableFormBeforeLoading: function()
- {
- },
- // Intended for overloading in derived classes
- _enableFormAfterLoading: function()
- {
- },
- });
- });
|