Added support for custom form changed callback
authorThierry Florac <tflorac@ulthar.net>
Thu, 13 Feb 2020 11:22:10 +0100
changeset 555 7d7ccf92d6af
parent 554 1a0218d4faac
child 558 fdfc4ac82db7
Added support for custom form changed callback
src/pyams_skin/resources/js/myams-core.js
src/pyams_skin/resources/js/myams-form.js
src/pyams_skin/resources/js/myams-require.js
src/pyams_skin/resources/js/myams.js
--- a/src/pyams_skin/resources/js/myams-core.js	Fri Nov 08 10:52:48 2019 +0100
+++ b/src/pyams_skin/resources/js/myams-core.js	Thu Feb 13 11:22:10 2020 +0100
@@ -7,7 +7,7 @@
  *
  * Custom administration and application skin tools
  * Released under Zope Public License ZPL 1.1
- * ©2014-2016 Thierry Florac <tflorac@ulthar.net>
+ * ©2014-2020 Thierry Florac <tflorac@ulthar.net>
  */
 
 "use strict";
@@ -227,6 +227,7 @@
 			enableMobile: false,
 			enableFastclick: false,
 			warnOnFormChange: false,
+			formChangedCallback: null,
 			ismobile: (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()))
 		};
 	}
--- a/src/pyams_skin/resources/js/myams-form.js	Fri Nov 08 10:52:48 2019 +0100
+++ b/src/pyams_skin/resources/js/myams-form.js	Thu Feb 13 11:22:10 2020 +0100
@@ -31,7 +31,9 @@
 				forms = $('FORM[data-ams-warn-on-change="true"]', element);
 			}
 			forms.each(function() {
-				var form = $(this);
+				var form = $(this),
+					formChangedCallback = form.data('ams-form-changed-callback') ||
+										  ams.formChangedCallback;
 				$('INPUT[type="text"], ' +
 				  'INPUT[type="checkbox"], ' +
 				  'INPUT[type="radio"], ' +
@@ -42,7 +44,8 @@
 						if (source.data('ams-ignore-change') !== true) {
 							var event = source.data('ams-changed-event') || 'change';
 							source.on(event, function () {
-								ams.form.setChanged($(this).parents('FORM'));
+								ams.form.setChanged(form);
+								ams.executeFunctionByName(formChangedCallback, form, source);
 							});
 						}
 				});
--- a/src/pyams_skin/resources/js/myams-require.js	Fri Nov 08 10:52:48 2019 +0100
+++ b/src/pyams_skin/resources/js/myams-require.js	Thu Feb 13 11:22:10 2020 +0100
@@ -7,7 +7,7 @@
  *
  * Custom administration and application skin tools
  * Released under Zope Public License ZPL 1.1
- * ©2014-2016 Thierry Florac <tflorac@ulthar.net>
+ * ©2014-2020 Thierry Florac <tflorac@ulthar.net>
  */
 
 "use strict";
@@ -227,6 +227,7 @@
 			enableMobile: false,
 			enableFastclick: false,
 			warnOnFormChange: false,
+			formChangedCallback: null,
 			ismobile: (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()))
 		};
 	}
--- a/src/pyams_skin/resources/js/myams.js	Fri Nov 08 10:52:48 2019 +0100
+++ b/src/pyams_skin/resources/js/myams.js	Thu Feb 13 11:22:10 2020 +0100
@@ -7,7 +7,7 @@
  *
  * Custom administration and application skin tools
  * Released under Zope Public License ZPL 1.1
- * ©2014-2016 Thierry Florac <tflorac@ulthar.net>
+ * ©2014-2020 Thierry Florac <tflorac@ulthar.net>
  */
 
 "use strict";
@@ -227,6 +227,7 @@
 			enableMobile: false,
 			enableFastclick: false,
 			warnOnFormChange: false,
+			formChangedCallback: null,
 			ismobile: (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()))
 		};
 	}
@@ -1797,7 +1798,9 @@
 				forms = $('FORM[data-ams-warn-on-change="true"]', element);
 			}
 			forms.each(function() {
-				var form = $(this);
+				var form = $(this),
+					formChangedCallback = form.data('ams-form-changed-callback') ||
+										  ams.formChangedCallback;
 				$('INPUT[type="text"], ' +
 				  'INPUT[type="checkbox"], ' +
 				  'INPUT[type="radio"], ' +
@@ -1808,7 +1811,8 @@
 						if (source.data('ams-ignore-change') !== true) {
 							var event = source.data('ams-changed-event') || 'change';
 							source.on(event, function () {
-								ams.form.setChanged($(this).parents('FORM'));
+								ams.form.setChanged(form);
+								ams.executeFunctionByName(formChangedCallback, form, source);
 							});
 						}
 				});