src/ztfy/myams/resources/js/myams.js
changeset 135 f7b7e3f21da6
parent 130 e3cb023c73b6
child 136 3ea42c4b9938
equal deleted inserted replaced
134:0f48f65f8290 135:f7b7e3f21da6
  1027 		 *  - @options: additional JSON-RPC method call parameters
  1027 		 *  - @options: additional JSON-RPC method call parameters
  1028 		 *  - @callback: name of a callback which will be called on server response
  1028 		 *  - @callback: name of a callback which will be called on server response
  1029 		 */
  1029 		 */
  1030 		post: function(method, data, options, callback) {
  1030 		post: function(method, data, options, callback) {
  1031 			ams.ajax.check($.jsonRpc,
  1031 			ams.ajax.check($.jsonRpc,
  1032 						   ams.baseURL + 'ext/jquery-jsonrpc' + (ams.devmode ? '.js' : '.min.js'),
  1032 						   ams.baseURL + 'ext/jquery-jsonrpc' + ams.devext + '.js',
  1033 						   function() {
  1033 						   function() {
  1034 								var result;
  1034 								var result;
  1035 								if (typeof(options) == 'function') {
  1035 								if (typeof(options) == 'function') {
  1036 									callback = options;
  1036 									callback = options;
  1037 									options = {};
  1037 									options = {};
  1042 									callback = options.callback;
  1042 									callback = options.callback;
  1043 								if (typeof(callback) == 'string')
  1043 								if (typeof(callback) == 'string')
  1044 									callback = ams.getFunctionByName(callback);
  1044 									callback = ams.getFunctionByName(callback);
  1045 								delete options.callback;
  1045 								delete options.callback;
  1046 
  1046 
       
  1047 								var result;
  1047 								var defaults = {
  1048 								var defaults = {
  1048 									url: ams.jsonrpc.getAddr(options.url),
  1049 									url: ams.jsonrpc.getAddr(options.url),
  1049 									type: 'post',
  1050 									type: 'post',
  1050 									cache: false,
  1051 									cache: false,
  1051 									method: method,
  1052 									method: method,
  1619 			} else if (errors instanceof Array) {
  1620 			} else if (errors instanceof Array) {
  1620 				var header = errors.length == 1 ? ams.i18n.ERROR_OCCURED : ams.i18n.ERRORS_OCCURED;
  1621 				var header = errors.length == 1 ? ams.i18n.ERROR_OCCURED : ams.i18n.ERRORS_OCCURED;
  1621 				ams.skin.alert(form, 'error', header, errors);
  1622 				ams.skin.alert(form, 'error', header, errors);
  1622 			} else {
  1623 			} else {
  1623 				$('.state-error', form).removeClass('state-error');
  1624 				$('.state-error', form).removeClass('state-error');
  1624 				header = errors.widgets && (errors.widgets.length > 1) ? ams.i18n.ERRORS_OCCURED : ams.i18n.ERROR_OCCURED;
  1625 				header = errors.error_header ||
       
  1626 						 (errors.widgets && (errors.widgets.length > 1) ? ams.i18n.ERRORS_OCCURED : ams.i18n.ERROR_OCCURED);
  1625 				var message = new Array();
  1627 				var message = new Array();
  1626 				var index;
  1628 				var index;
  1627 				for (index in errors.messages) {
  1629 				for (index in errors.messages) {
  1628 					if (!$.isNumeric(index))
  1630 					if (!$.isNumeric(index))
  1629 						continue;
  1631 						continue;
  1630 					message.push(errors.messages[index].message || errors.messages[index]);
  1632 					if (errors.messages[index].header) {
       
  1633 						message.push('<strong>' + errors.messages[index].header + '</strong><br />' + errors.messages[index].message);
       
  1634 					} else {
       
  1635 						message.push(errors.messages[index].message || errors.messages[index]);
       
  1636 					}
  1631 				}
  1637 				}
  1632 				for (index in errors.widgets) {
  1638 				for (index in errors.widgets) {
  1633 					if (!$.isNumeric(index))
  1639 					if (!$.isNumeric(index))
  1634 						continue;
  1640 						continue;
  1635 					// set widget status message
  1641 					// set widget status message
  1650 						$('li:nth-child(' + tab_index + ')', nav_tabs).removeClassPrefix('state-')
  1656 						$('li:nth-child(' + tab_index + ')', nav_tabs).removeClassPrefix('state-')
  1651 																	  .addClass('state-error');
  1657 																	  .addClass('state-error');
  1652 						$('li.state-error:first a', form).click();
  1658 						$('li.state-error:first a', form).click();
  1653 					}
  1659 					}
  1654 				}
  1660 				}
  1655 				ams.skin.alert(form, 'error', header, message, errors.error_message);
  1661 				ams.skin.alert(form, errors.error_level || 'error', header, message, errors.error_message);
  1656 			}
  1662 			}
  1657 		}
  1663 		}
  1658 	};
  1664 	};
  1659 
  1665 
  1660 
  1666 
  2661 				if (datepickers.length > 0) {
  2667 				if (datepickers.length > 0) {
  2662 					ams.ajax.check($.fn.datetimepicker,
  2668 					ams.ajax.check($.fn.datetimepicker,
  2663 								   ams.baseURL + 'ext/jquery-datetimepicker' + ams.devext + '.js',
  2669 								   ams.baseURL + 'ext/jquery-datetimepicker' + ams.devext + '.js',
  2664 								   function(first_load) {
  2670 								   function(first_load) {
  2665 										if (first_load) {
  2671 										if (first_load) {
  2666 											ams.getCSS(ams.baseURL + '../css/ext/jquery-datetimepicker' + (ams.devmode ? '.css' : '.min.css'), 'jquery-datetimepicker');
  2672 											ams.getCSS(ams.baseURL + '../css/ext/jquery-datetimepicker' + ams.devext + '.css', 'jquery-datetimepicker');
  2667 											ams.dialog.registerHideCallback(ams.helpers.datetimepickerDialogHiddenCallback);
  2673 											ams.dialog.registerHideCallback(ams.helpers.datetimepickerDialogHiddenCallback);
  2668 										}
  2674 										}
  2669 										datepickers.each(function() {
  2675 										datepickers.each(function() {
  2670 											var input = $(this);
  2676 											var input = $(this);
  2671 											var data = input.data();
  2677 											var data = input.data();
  2693 				if (datetimepickers.length > 0) {
  2699 				if (datetimepickers.length > 0) {
  2694 					ams.ajax.check($.fn.datetimepicker,
  2700 					ams.ajax.check($.fn.datetimepicker,
  2695 								   ams.baseURL + 'ext/jquery-datetimepicker' + ams.devext + '.js',
  2701 								   ams.baseURL + 'ext/jquery-datetimepicker' + ams.devext + '.js',
  2696 								   function(first_load) {
  2702 								   function(first_load) {
  2697 										if (first_load) {
  2703 										if (first_load) {
  2698 											ams.getCSS(ams.baseURL + '../css/ext/jquery-datetimepicker' + (ams.devmode ? '.css' : '.min.css'), 'jquery-datetimepicker');
  2704 											ams.getCSS(ams.baseURL + '../css/ext/jquery-datetimepicker' + ams.devext + '.css', 'jquery-datetimepicker');
  2699 											ams.dialog.registerHideCallback(ams.helpers.datetimepickerDialogHiddenCallback);
  2705 											ams.dialog.registerHideCallback(ams.helpers.datetimepickerDialogHiddenCallback);
  2700 										}
  2706 										}
  2701 										datetimepickers.each(function() {
  2707 										datetimepickers.each(function() {
  2702 											var input = $(this);
  2708 											var input = $(this);
  2703 											var data = input.data();
  2709 											var data = input.data();
  2725 				if (timepickers.length > 0) {
  2731 				if (timepickers.length > 0) {
  2726 					ams.ajax.check($.fn.datetimepicker,
  2732 					ams.ajax.check($.fn.datetimepicker,
  2727 								   ams.baseURL + 'ext/jquery-datetimepicker' + ams.devext + '.js',
  2733 								   ams.baseURL + 'ext/jquery-datetimepicker' + ams.devext + '.js',
  2728 								   function(first_load) {
  2734 								   function(first_load) {
  2729 										if (first_load) {
  2735 										if (first_load) {
  2730 											ams.getCSS(ams.baseURL + '../css/ext/jquery-datetimepicker' + (ams.devmode ? '.css' : '.min.css'), 'jquery-datetimepicker');
  2736 											ams.getCSS(ams.baseURL + '../css/ext/jquery-datetimepicker' + ams.devext + '.css', 'jquery-datetimepicker');
  2731 											ams.dialog.registerHideCallback(ams.helpers.datetimepickerDialogHiddenCallback);
  2737 											ams.dialog.registerHideCallback(ams.helpers.datetimepickerDialogHiddenCallback);
  2732 										}
  2738 										}
  2733 										timepickers.each(function() {
  2739 										timepickers.each(function() {
  2734 											var input = $(this);
  2740 											var input = $(this);
  2735 											var data = input.data();
  2741 											var data = input.data();
  3820 				url: url,
  3826 				url: url,
  3821 				dataType: 'html',
  3827 				dataType: 'html',
  3822 				cache: false,
  3828 				cache: false,
  3823 				beforeSend: function() {
  3829 				beforeSend: function() {
  3824 					ams.skin.cleanContainer(container);
  3830 					ams.skin.cleanContainer(container);
  3825 					container.html('<h1><i class="fa fa-cog fa-spin"></i> Loading... </h1>');
  3831 					container.html('<h1 class="loading"><i class="fa fa-cog fa-spin"></i> Loading... </h1>');
  3826 					if (container[0] == $('#content')[0]) {
  3832 					if (container[0] == $('#content')[0]) {
  3827 						ams.skin._drawBreadCrumb();
  3833 						ams.skin._drawBreadCrumb();
  3828 						document.title = $('.breadcrumb LI:last-child').text();
  3834 						document.title = $('.breadcrumb LI:last-child').text();
  3829 						$('html, body').animate({scrollTop: 0}, 'fast');
  3835 						$('html, body').animate({scrollTop: 0}, 'fast');
  3830 					} else {
  3836 					} else {
  3836 						ams.executeFunctionByName(callback, this, data, status, request, options);
  3842 						ams.executeFunctionByName(callback, this, data, status, request, options);
  3837 					else {
  3843 					else {
  3838 						var request_data = ams.ajax.getResponse(request);
  3844 						var request_data = ams.ajax.getResponse(request);
  3839 						var data_type = request_data.content_type;
  3845 						var data_type = request_data.content_type;
  3840 						var result = request_data.data;
  3846 						var result = request_data.data;
       
  3847 						$('.loading', container).remove();
  3841 						switch (data_type) {
  3848 						switch (data_type) {
  3842 							case 'json':
  3849 							case 'json':
  3843 								ams.ajax.handleJSON(result, container);
  3850 								ams.ajax.handleJSON(result, container);
  3844 								break;
  3851 								break;
  3845 							case 'script':
  3852 							case 'script':