mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°1881.1 Portal: Add DOM attribute (and widget helper) on object form that fields have been touched
This commit is contained in:
@@ -1,19 +1,20 @@
|
||||
// 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/>
|
||||
/*
|
||||
* Copyright (C) 2013-2019 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
|
||||
*/
|
||||
|
||||
//iTop Field set
|
||||
//Used by itop.form_handler and itop.subform_field to list their fields
|
||||
@@ -171,11 +172,15 @@ $(function()
|
||||
this.options.is_valid = false;
|
||||
}
|
||||
|
||||
// Request update on dependent fields
|
||||
var oRequestedFields = this._getRequestedFields(oData.name);
|
||||
if(oRequestedFields.length > 0)
|
||||
{
|
||||
this.element.trigger('update_fields', {form_path: this.options.form_path, requested_fields: oRequestedFields});
|
||||
}
|
||||
|
||||
// Notify form that fields have been touched
|
||||
this.element.trigger('fields_touched');
|
||||
},
|
||||
_onUpdateForm: function(oEvent, oData)
|
||||
{
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/*
|
||||
* Copyright (C) 2013-2019 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
|
||||
*/
|
||||
|
||||
//iTop Form handler
|
||||
;
|
||||
$(function()
|
||||
@@ -30,6 +48,9 @@ $(function()
|
||||
this.element.bind('update_fields', function(oEvent, oData){
|
||||
me._onUpdateFields(oEvent, oData);
|
||||
});
|
||||
this.element.bind('fields_touched', function(oEvent){
|
||||
me._onFieldsTouched(oEvent);
|
||||
});
|
||||
|
||||
// Binding buttons
|
||||
if(this.options.submit_btn_selector !== null)
|
||||
@@ -65,10 +86,15 @@ $(function()
|
||||
{
|
||||
this._super( key, value );
|
||||
},
|
||||
|
||||
// Methods
|
||||
getCurrentValues: function()
|
||||
{
|
||||
return this.options.field_set.triggerHandler('get_current_values');
|
||||
},
|
||||
|
||||
// Events callback
|
||||
// - Update fields depending on the update ones
|
||||
_onUpdateFields: function(oEvent, oData)
|
||||
{
|
||||
var me = this;
|
||||
@@ -109,6 +135,11 @@ $(function()
|
||||
.fail(function(oData){ me._onUpdateFailure(oData, sFormPath); })
|
||||
.always(function(oData){ me._onUpdateAlways(oData, sFormPath); });
|
||||
},
|
||||
// - Callback when some fields have been touched
|
||||
_onFieldsTouched: function(oEvent)
|
||||
{
|
||||
this.element.attr('data-fields-touched', 'true');
|
||||
},
|
||||
// Intended for overloading in derived classes
|
||||
_onSubmitClick: function(oEvent)
|
||||
{
|
||||
@@ -136,6 +167,8 @@ $(function()
|
||||
this.element.find('[data-form-path="' + sFormPath + '"]').trigger('validate');
|
||||
this._enableFormAfterLoading();
|
||||
},
|
||||
|
||||
// Helpers
|
||||
// Intended for overloading in derived classes
|
||||
_disableFormBeforeLoading: function()
|
||||
{
|
||||
@@ -144,7 +177,13 @@ $(function()
|
||||
_enableFormAfterLoading: function()
|
||||
{
|
||||
},
|
||||
showOptions: function() // Debug helper
|
||||
// Returns true if the form fields have been touched
|
||||
_hasBeenTouched: function()
|
||||
{
|
||||
return (this.element.attr('data-fields-touched') === 'true');
|
||||
},
|
||||
// Debug helper
|
||||
showOptions: function()
|
||||
{
|
||||
console.log(this.options);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user