Added "notify" status to JSON response to be able to fire a given event
authorThierry Florac <thierry.florac@onf.fr>
Mon, 15 Sep 2014 13:05:10 +0200
changeset 60 006912c0dd67
parent 59 8c8d6e681c70
child 61 d2ad83a628a0
Added "notify" status to JSON response to be able to fire a given event
src/ztfy/myams/resources/js/myams.js
--- a/src/ztfy/myams/resources/js/myams.js	Mon Sep 15 13:04:35 2014 +0200
+++ b/src/ztfy/myams/resources/js/myams.js	Mon Sep 15 13:05:10 2014 +0200
@@ -759,6 +759,7 @@
 				case 'message':
 				case 'messagebox':
 					break;
+				case 'notify':
 				case 'callback':
 				case 'callbacks':
 					if (result.close_form != false)
@@ -776,6 +777,8 @@
 					ams.skin.loadURL(url, result.target || target || '#content');
 					break;
 				case 'redirect':
+					if (result.close_form == true)
+						ams.dialog.close(form);
 					url = result.location;
 					if (result.window) {
 						window.open(url, result.window, result.options);
@@ -824,6 +827,8 @@
 										 timeout: message.timeout || 10000});
 				}
 			}
+			if (result.event)
+				form.trigger(result.event, result.event_options);
 			if (result.callback)
 				ams.executeFunctionByName(result.callback, form, result.options);
 			if (result.callbacks) {
@@ -1556,6 +1561,14 @@
 	 */
 	MyAMS.helpers = {
 
+		/** Clear Select2 slection */
+		select2ClearSelection: function() {
+			var source = $(this);
+			var label = source.parents('label');
+			var target = source.data('ams-select2-target');
+			$('INPUT[name="' + target + '"]', label).data('select2').val('');
+		},
+
 		/** Select2 selection formatter */
 		select2FormatSelection: function(object, container) {
 			if (object instanceof Array) {
@@ -1806,6 +1819,14 @@
 								$('.fa', legend).removeClass(data.amsSwitcherPlusClass || 'fa-plus')
 												.addClass(data.amsSwitcherMinusClass || 'fa-minus');
 								legend.trigger('ams.switcher.opened', [legend]);
+								var id = legend.attr('id');
+								if (id) {
+									$('legend.switcher[data-ams-switcher-sync="'+id+'"]', fieldset).each(function() {
+										var switcher = $(this);
+										if (switcher.parents('fieldset').hasClass('switched'))
+											switcher.click();
+									});
+								}
 							} else {
 								fieldset.addClass('switched');
 								$('.fa', legend).removeClass(data.amsSwitcherMinusClass || 'fa-minus')