src/myams/resources/js/myams.js
changeset 21 d1946c8a78b5
parent 18 575d9fadef6e
child 24 5ea89334a159
equal deleted inserted replaced
20:73ca3a7bc4e5 21:d1946c8a78b5
     1 /*
     1 /*
     2  * MyAMS
     2  * MyAMS
     3  * « My Application Management Skin »
     3  * « My Application Management Skin »
     4  *
     4  *
     5  * Version: 0.1.42 (rev. 1)
     5  * Version: 0.1.43 (rev. 1)
     6  * A bootstrap based application/administration skin
     6  * A bootstrap based application/administration skin
     7  *
     7  *
     8  * Custom administration and application skin tools
     8  * Custom administration and application skin tools
     9  * Released under Zope Public License ZPL 1.1
     9  * Released under Zope Public License ZPL 1.1
    10  * ©2014-2020 Thierry Florac <tflorac@ulthar.net>
    10  * ©2014-2020 Thierry Florac <tflorac@ulthar.net>
  5080 			if (charts.length > 0) {
  5080 			if (charts.length > 0) {
  5081 				ams.ajax && ams.ajax.check([window.Flot, $.color],
  5081 				ams.ajax && ams.ajax.check([window.Flot, $.color],
  5082 					[ams.baseURL + 'ext/flot/jquery.canvaswrapper' + ams.devext + '.js',
  5082 					[ams.baseURL + 'ext/flot/jquery.canvaswrapper' + ams.devext + '.js',
  5083 					 ams.baseURL + 'ext/flot/jquery.colorhelpers' + ams.devext + '.js'],
  5083 					 ams.baseURL + 'ext/flot/jquery.colorhelpers' + ams.devext + '.js'],
  5084 					function () {
  5084 					function () {
  5085 						ams.ajax.check($.fn.plot,
  5085 						ams.ajax.check($.plot,
  5086 							ams.baseURL + 'ext/flot/jquery.flot' + ams.devext + '.js',
  5086 							ams.baseURL + 'ext/flot/jquery.flot' + ams.devext + '.js',
  5087 							function () {
  5087 							function () {
  5088 								charts.each(function () {
  5088 								ams.ajax.check($.plot.uiConstants,
  5089 
  5089 									ams.baseURL + 'ext/flot/jquery.flot.uiConstants' + ams.devext + '.js',
  5090 									var chart = $(this),
  5090 									function() {
  5091 										data = chart.data(),
  5091 										charts.each(function () {
  5092 										dataOptions = {},
  5092 
  5093 										plugin,
  5093 											var chart = $(this),
  5094 										flotPlugins = (data.amsChartPlugins || '').split(/\s+/);
  5094 												data = chart.data(),
  5095 
  5095 												dataOptions = {},
  5096 									function checkPlugin(plugin) {
  5096 												plugin,
  5097 										for (var index in $.plot.plugins) {
  5097 												flotPlugins = (data.amsChartPlugins || '').split(/\s+/);
  5098 											if ($.plot.plugins.hasOwnProperty(index)) {
  5098 
  5099 												var pluginInfo = $.plot.plugins[index];
  5099 											function checkPlugin(plugin) {
  5100 												if (pluginInfo.name === plugin) {
  5100 												for (var index in $.plot.plugins) {
  5101 													return pluginInfo;
  5101 													if ($.plot.plugins.hasOwnProperty(index)) {
       
  5102 														var pluginInfo = $.plot.plugins[index];
       
  5103 														if (pluginInfo.name === plugin) {
       
  5104 															return pluginInfo;
       
  5105 														}
       
  5106 													}
       
  5107 												}
       
  5108 												return null;
       
  5109 											}
       
  5110 
       
  5111 											function initChart() {
       
  5112 												var settings = $.extend({}, dataOptions, data.amsChartOptions);
       
  5113 												settings = ams.executeFunctionByName(data.amsChartInitCallback, chart, settings) || settings;
       
  5114 												var chartData = data.amsChartData,
       
  5115 													chartDataLoader = data.amsChartDataLoader;
       
  5116 												if (chartDataLoader) {
       
  5117 													$.getJSON(chartDataLoader, chartData).done(function (data) {
       
  5118 														settings = $.extend({}, settings, data.settings);
       
  5119 														createChart(data.data, settings);
       
  5120 													});
       
  5121 												} else {
       
  5122 													createChart(data, settings);
  5102 												}
  5123 												}
  5103 											}
  5124 											}
  5104 										}
  5125 
  5105 										return null;
  5126 											function createChart(chartData, settings) {
  5106 									}
  5127 												chartData = ams.executeFunctionByName(data.amsChartInitData, chart, chartData) || chartData;
  5107 
  5128 												plugin = chart.plot(chartData, settings);
  5108 									function initChart() {
  5129 												ams.executeFunctionByName(data.amsChartAfterInitCallback, chart, plugin, settings);
  5109 										var settings = $.extend({}, dataOptions, data.amsChartOptions);
  5130 											}
  5110 										settings = ams.executeFunctionByName(data.amsChartInitCallback, chart, settings) || settings;
  5131 
  5111 										var chartData = data.amsChartData,
  5132 											var deferred = [];
  5112 											chartDataLoader = data.amsChartDataLoader;
  5133 											if (flotPlugins.length > 0) {
  5113 										if (chartDataLoader) {
  5134 												for (var index in flotPlugins) {
  5114 											$.getJSON(chartDataLoader, chartData).done(function (data) {
  5135 													if (flotPlugins.hasOwnProperty(index)) {
  5115 												settings = $.extend({}, settings, data.settings);
  5136 														var pluginName = flotPlugins[index];
  5116 												createChart(data.data, settings);
  5137 														if (!checkPlugin(pluginName)) {
  5117 											});
  5138 															deferred.push(ams.getScript(ams.baseURL + 'ext/flot/jquery.flot.' + pluginName + ams.devext + '.js'));
  5118 										} else {
  5139 														}
  5119 											createChart(data, settings);
  5140 													}
  5120 										}
       
  5121 									}
       
  5122 
       
  5123 									function createChart(chartData, settings) {
       
  5124 										chartData = ams.executeFunctionByName(data.amsChartInitData, chart, chartData) || chartData;
       
  5125 										plugin = chart.plot(chartData, settings);
       
  5126 										ams.executeFunctionByName(data.amsChartAfterInitCallback, chart, plugin, settings);
       
  5127 									}
       
  5128 
       
  5129 									var deferred = [];
       
  5130 									if (flotPlugins.length > 0) {
       
  5131 										for (var index in flotPlugins) {
       
  5132 											if (flotPlugins.hasOwnProperty(index)) {
       
  5133 												var pluginName = flotPlugins[index];
       
  5134 												if (!checkPlugin(pluginName)) {
       
  5135 													deferred.push(ams.getScript(ams.baseURL + 'ext/flot/jquery.flot.' + pluginName + ams.devext + '.js'));
       
  5136 												}
  5141 												}
  5137 											}
  5142 											}
  5138 										}
  5143 											if (deferred.length > 0) {
  5139 									}
  5144 												$.when.apply($, deferred).then(function () {
  5140 									if (deferred.length > 0) {
  5145 													initChart();
  5141 										$.when.apply($, deferred).then(function () {
  5146 												})
  5142 											initChart();
  5147 											} else {
  5143 										})
  5148 												initChart();
  5144 									} else {
  5149 											}
  5145 										initChart();
  5150 										});
  5146 									}
       
  5147 								});
  5151 								});
  5148 							});
  5152 							});
  5149 					});
  5153 					});
  5150 			}
  5154 			}
  5151 		},
  5155 		},