src/ztfy/myams/resources/js/myams.js
changeset 154 0fff49179f6d
parent 148 8c340adcf888
child 156 61176c64158d
equal deleted inserted replaced
153:35ddbcfb3008 154:0fff49179f6d
  1665 				result = request_data.data;
  1665 				result = request_data.data;
  1666 			}
  1666 			}
  1667 
  1667 
  1668 			var target;
  1668 			var target;
  1669 			if (button) {
  1669 			if (button) {
  1670 				target = $(button.amsFormSubmitTarget || data.amsFormSubmitTarget || '#content');
  1670 				target = $(button.data('ams-form-submit-target') || data.amsFormSubmitTarget || '#content');
  1671 			} else {
  1671 			} else {
  1672 				target = $(data.amsFormSubmitTarget || '#content');
  1672 				target = $(data.amsFormSubmitTarget || '#content');
  1673 			}
  1673 			}
  1674 
  1674 
  1675 			switch (data_type) {
  1675 			switch (data_type) {
  1785 				$('.state-error', form).removeClass('state-error');
  1785 				$('.state-error', form).removeClass('state-error');
  1786 				header = errors.error_header ||
  1786 				header = errors.error_header ||
  1787 						 (errors.widgets && (errors.widgets.length > 1) ? ams.i18n.ERRORS_OCCURED : ams.i18n.ERROR_OCCURED);
  1787 						 (errors.widgets && (errors.widgets.length > 1) ? ams.i18n.ERRORS_OCCURED : ams.i18n.ERROR_OCCURED);
  1788 				var message = [];
  1788 				var message = [];
  1789 				var index;
  1789 				var index;
  1790 				for (index=0; index < errors.messages.length; index++) {
  1790 				if (errors.messages) {
  1791 					var msg = errors.messages[index];
  1791 					for (index = 0; index < errors.messages.length; index++) {
  1792 					if (msg.header) {
  1792 						var msg = errors.messages[index];
  1793 						message.push('<strong>' + msg.header + '</strong><br />' + msg.message);
  1793 						if (msg.header) {
  1794 					} else {
  1794 							message.push('<strong>' + msg.header + '</strong><br />' + msg.message);
  1795 						message.push(msg.message || msg);
  1795 						} else {
       
  1796 							message.push(msg.message || msg);
       
  1797 						}
  1796 					}
  1798 					}
  1797 				}
  1799 				}
  1798 				if (errors.widgets) {
  1800 				if (errors.widgets) {
  1799 					for (index = 0; index < errors.widgets.length; index++) {
  1801 					for (index = 0; index < errors.widgets.length; index++) {
  1800 						// set widget status message
  1802 						// set widget status message
  2264 					disabled.push(plugins[index]);
  2266 					disabled.push(plugins[index]);
  2265 				}
  2267 				}
  2266 			});
  2268 			});
  2267 
  2269 
  2268 			// Load and register new plug-ins
  2270 			// Load and register new plug-ins
  2269 			var plugin;
       
  2270 			$('[data-ams-plugins]', element).each(function() {
  2271 			$('[data-ams-plugins]', element).each(function() {
  2271 				var source = $(this);
  2272 				var source = $(this);
  2272 				var plugins = {};
  2273 				var plugins = {};
  2273 				var name;
  2274 				var name;
  2274 				if (typeof(source.data('ams-plugins')) === 'string') {
  2275 				if (typeof(source.data('ams-plugins')) === 'string') {
  2284 						};
  2285 						};
  2285 					}
  2286 					}
  2286 				} else {
  2287 				} else {
  2287 					plugins = source.data('ams-plugins');
  2288 					plugins = source.data('ams-plugins');
  2288 				}
  2289 				}
  2289 
       
  2290 				function executePlugin() {
       
  2291 					var callback = plugin.callback;
       
  2292 					if (callback) {
       
  2293 						var called = ams.getFunctionByName(callback);
       
  2294 						if (plugin.register !== false) {
       
  2295 							ams.plugins.enabled[name] = called;
       
  2296 						}
       
  2297 					} else {
       
  2298 						if (plugin.register !== false) {
       
  2299 							ams.plugins.enabled[name] = null;
       
  2300 						}
       
  2301 					}
       
  2302 					var css = plugin.css;
       
  2303 					if (css) {
       
  2304 						ams.getCSS(css, name + '_css');
       
  2305 					}
       
  2306 				}
       
  2307 
       
  2308 				for (name in plugins) {
  2290 				for (name in plugins) {
  2309 					if (ams.plugins.enabled[name] === undefined) {
  2291 					if (ams.plugins.enabled[name] === undefined) {
  2310 						plugin = plugins[name];
  2292 						var plugin = plugins[name];
  2311 						ams.getScript(plugin.src, executePlugin, {
  2293 						ams.getScript(plugin.src, function() {
       
  2294 							var callback = plugin.callback;
       
  2295 							if (callback) {
       
  2296 								var called = ams.getFunctionByName(callback);
       
  2297 								if (plugin.register !== false)
       
  2298 									ams.plugins.enabled[name] = called;
       
  2299 							} else {
       
  2300 								if (plugin.register !== false)
       
  2301 									ams.plugins.enabled[name] = null;
       
  2302 							}
       
  2303 							var css = plugin['css'];
       
  2304 							if (css) {
       
  2305 								ams.getCSS(css, name + '_css');
       
  2306 							}
       
  2307 						}, {
  2312 							async: plugin.async === undefined ? true : plugin.async
  2308 							async: plugin.async === undefined ? true : plugin.async
  2313 						});
  2309 						});
  2314 					}
  2310 					}
  2315 				}
  2311 				}
  2316 			});
  2312 			});
  2321 					continue;
  2317 					continue;
  2322 				}
  2318 				}
  2323 				if (disabled.indexOf(index) >= 0) {
  2319 				if (disabled.indexOf(index) >= 0) {
  2324 					continue;
  2320 					continue;
  2325 				}
  2321 				}
  2326 				plugin = ams.plugins.enabled[index];
  2322 				var plugin = ams.plugins.enabled[index];
  2327 				if (typeof(plugin) === 'function') {
  2323 				if (typeof(plugin) === 'function') {
  2328 					plugin(element);
  2324 					plugin(element);
  2329 				}
  2325 				}
  2330 			}
  2326 			}
  2331 		},
  2327 		},