/pimcore/static/js/pimcore/report/custom/definitions/analytics.js

https://github.com/timglabisch/pimcore · JavaScript · 312 lines · 258 code · 41 blank · 13 comment · 12 complexity · 49698aaa9b444d08b99ee8903c81d6b8 MD5 · raw file

  1. /**
  2. * Pimcore
  3. *
  4. * LICENSE
  5. *
  6. * This source file is subject to the new BSD license that is bundled
  7. * with this package in the file LICENSE.txt.
  8. * It is also available through the world-wide-web at this URL:
  9. * http://www.pimcore.org/license
  10. *
  11. * @copyright Copyright (c) 2009-2010 elements.at New Media Solutions GmbH (http://www.elements.at)
  12. * @license http://www.pimcore.org/license New BSD License
  13. */
  14. pimcore.registerNS("pimcore.report.custom.definition.analytics");
  15. pimcore.report.custom.definition.analytics = Class.create({
  16. element: null,
  17. sourceDefinitionData: null,
  18. initialize: function (sourceDefinitionData, key, deleteControl, columnSettingsCallback) {
  19. sourceDefinitionData = sourceDefinitionData ? sourceDefinitionData : {filters: '', sort: '', startDate: '', relativeStartDate: '', relativeEndDate: '', endDate: '', relativeStartDate: '', dimension: '', metric: '', segment: '', profileId: ''};
  20. if (sourceDefinitionData.startDate) {
  21. var startDate = new Date();
  22. startDate.setTime(sourceDefinitionData.startDate);
  23. sourceDefinitionData.startDate = startDate;
  24. }
  25. if (sourceDefinitionData.endDate) {
  26. var endDate = new Date();
  27. endDate.setTime(sourceDefinitionData.endDate);
  28. sourceDefinitionData.endDate = endDate;
  29. }
  30. this.sourceDefinitionData = sourceDefinitionData;
  31. var profileLoaded = false;
  32. var dimensionLoaded = false;
  33. var metricLoaded = false;
  34. var segmentLoaded = false;
  35. this.dimensionStore = new Ext.data.JsonStore({
  36. autoDestroy: true,
  37. url: "/admin/reports/analytics/get-dimensions",
  38. root: "data",
  39. idProperty: "id",
  40. fields: ["name", "id"],
  41. listeners: {
  42. load: function () {
  43. var dimensions = new Ext.ux.form.MultiSelect({
  44. name: "dimension",
  45. triggerAction: "all",
  46. editable: false,
  47. fieldLabel: t("dimension"),
  48. store: this.dimensionStore,
  49. displayField: "name",
  50. valueField: "id",
  51. width: 300,
  52. value: sourceDefinitionData.dimension,
  53. listeners: {
  54. change: columnSettingsCallback
  55. }
  56. });
  57. var index = 1;
  58. this.element.insert(index, dimensions);
  59. this.element.doLayout();
  60. dimensionLoaded = true;
  61. }.bind(this)
  62. }
  63. });
  64. this.dimensionStore.load();
  65. this.metricsStore = new Ext.data.JsonStore({
  66. autoDestroy: true,
  67. url: "/admin/reports/analytics/get-metrics",
  68. root: "data",
  69. idProperty: "id",
  70. fields: ["name", "id"],
  71. listeners: {
  72. load: function () {
  73. var metrics = new Ext.ux.form.MultiSelect({
  74. name: "metric",
  75. triggerAction: "all",
  76. editable: false,
  77. fieldLabel: t("metric"),
  78. store: this.metricsStore,
  79. displayField: "name",
  80. valueField: "id",
  81. width: 300,
  82. value: sourceDefinitionData.metric,
  83. listeners: {
  84. change: columnSettingsCallback
  85. }
  86. });
  87. var index = 1;
  88. if (dimensionLoaded) {
  89. index++;
  90. }
  91. this.element.insert(index, metrics);
  92. this.element.doLayout();
  93. metricLoaded = true;
  94. }.bind(this)
  95. }
  96. });
  97. this.metricsStore.load();
  98. this.segementsStore = new Ext.data.JsonStore({
  99. autoDestroy: true,
  100. autoLoad: true,
  101. url: "/admin/reports/analytics/get-segments",
  102. root: "data",
  103. idProperty: "id",
  104. fields: ["name", "id"],
  105. listeners: {
  106. load: function () {
  107. if (segmentLoaded) {
  108. return;
  109. }
  110. var segments = new Ext.form.ComboBox({
  111. name: "segment",
  112. triggerAction: "all",
  113. editable: false,
  114. fieldLabel: t("segment"),
  115. store: this.segementsStore,
  116. displayField: "name",
  117. valueField: "id",
  118. mode: "local",
  119. width: 300,
  120. value: sourceDefinitionData.segment,
  121. listeners: {
  122. change: columnSettingsCallback
  123. }
  124. });
  125. var index = 1;
  126. if (dimensionLoaded) {
  127. index++;
  128. }
  129. if (metricLoaded) {
  130. index++;
  131. }
  132. segmentLoaded = true;
  133. this.element.insert(index, segments);
  134. this.element.doLayout();
  135. }.bind(this)
  136. }
  137. });
  138. this.segementsStore.load();
  139. var time = new Date().getTime();
  140. this.element = new Ext.form.FormPanel({
  141. key: key,
  142. bodyStyle: "padding:10px;",
  143. layout: "pimcoreform",
  144. autoHeight: true,
  145. border: false,
  146. tbar: deleteControl, //this.getDeleteControl("SQL", key),
  147. labelWidth: 200,
  148. items: [
  149. {
  150. xtype: "combo",
  151. name: "profileId",
  152. fieldLabel: t('profile'),
  153. id: "custom_reports_analytics_" + time + "_profileId",
  154. typeAhead: true,
  155. displayField: 'name',
  156. mode: 'local',
  157. store: new Ext.data.JsonStore({
  158. autoDestroy: true,
  159. autoLoad: true,
  160. url: "/admin/reports/analytics/get-profiles",
  161. root: "data",
  162. idProperty: "id",
  163. fields: ["name", "id"],
  164. listeners: {
  165. load: function () {
  166. Ext.getCmp("custom_reports_analytics_" + time + "_profileId").setValue(sourceDefinitionData.profileId);
  167. }.bind(this, time, sourceDefinitionData)
  168. }
  169. }),
  170. valueField: 'id',
  171. forceSelection: true,
  172. triggerAction: 'all',
  173. width: 300,
  174. value: sourceDefinitionData.profileId,
  175. listeners: {
  176. change: columnSettingsCallback
  177. }
  178. },
  179. {
  180. xtype: "textfield",
  181. name: "filters",
  182. fieldLabel: "Filters",
  183. value: (sourceDefinitionData.filters ),
  184. width: 250,
  185. enableKeyEvents: true,
  186. listeners: {
  187. change: columnSettingsCallback
  188. }
  189. },
  190. {
  191. xtype: "textfield",
  192. name: "sort",
  193. fieldLabel: "Sort",
  194. value: (sourceDefinitionData.sort),
  195. width: 250,
  196. enableKeyEvents: true,
  197. listeners: {
  198. change: columnSettingsCallback
  199. }
  200. },
  201. {
  202. xtype: 'spacer',
  203. height: 30
  204. },
  205. {
  206. xtype: "datefield",
  207. name: "startDate",
  208. fieldLabel: t("start_date"),
  209. value: (sourceDefinitionData.startDate),
  210. width: 250,
  211. enableKeyEvents: true,
  212. listeners: {
  213. change: columnSettingsCallback
  214. }
  215. },
  216. {
  217. xtype: "textfield",
  218. name: "relativeStartDate",
  219. fieldLabel: t("start_date_relative") + '<br/><small>'+t("relative_date_description")+"</small>",
  220. value: (sourceDefinitionData.relativeStartDate),
  221. width: 250,
  222. enableKeyEvents: true,
  223. listeners: {
  224. change: columnSettingsCallback
  225. }
  226. },{
  227. xtype: 'spacer',
  228. height: 30
  229. },
  230. {
  231. xtype: "datefield",
  232. name: "endDate",
  233. fieldLabel: t("end_date"),
  234. value: (sourceDefinitionData.endDate),
  235. width: 250,
  236. enableKeyEvents: true,
  237. listeners: {
  238. change: columnSettingsCallback
  239. }
  240. },{
  241. xtype: "textfield",
  242. name: "relativeEndDate",
  243. fieldLabel: t("end_date_relative") + '<br/><small>'+t("relative_date_description")+"</small>",
  244. value: (sourceDefinitionData.relativeEndDate),
  245. width: 250,
  246. enableKeyEvents: true,
  247. listeners: {
  248. change: columnSettingsCallback
  249. }
  250. }
  251. ]
  252. });
  253. },
  254. getElement: function () {
  255. return this.element;
  256. },
  257. getValues: function () {
  258. var values = this.element.getForm().getFieldValues();
  259. if (typeof values.metric == 'undefined' || typeof values.dimension == 'undefined') {
  260. values = this.sourceDefinitionData;
  261. }
  262. values.type = "analytics";
  263. if (values.startDate) {
  264. values.startDate = new Date(values.startDate).getTime();
  265. }
  266. if (values.endDate) {
  267. values.endDate = new Date(values.endDate).getTime();
  268. }
  269. return values;
  270. }
  271. });