From 8ef67dee3b3c2db8aea778f6f006be1f4715e534 Mon Sep 17 00:00:00 2001 From: Molkobain Date: Fri, 16 Aug 2019 17:02:40 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B01881.1=20Portal:=20Add=20DOM=20attribute?= =?UTF-8?q?=20(and=20widget=20helper)=20on=20object=20form=20that=20fields?= =?UTF-8?q?=20have=20been=20touched?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/field_set.js | 37 +++++++++++++++++++++---------------- js/form_handler.js | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 17 deletions(-) diff --git a/js/field_set.js b/js/field_set.js index 5f4d3f3f3..cbc436aa6 100644 --- a/js/field_set.js +++ b/js/field_set.js @@ -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 +/* + * 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) { diff --git a/js/form_handler.js b/js/form_handler.js index 868e98694..5757860f4 100644 --- a/js/form_handler.js +++ b/js/form_handler.js @@ -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); }