SFDetailsWidget.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*##############################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################## */
  16. define([
  17. "exports",
  18. "dojo/_base/declare",
  19. "dojo/_base/lang",
  20. "dojo/_base/array",
  21. "dojo/dom",
  22. "dojo/dom-attr",
  23. "dojo/dom-class",
  24. "dojo/dom-form",
  25. "dojo/query",
  26. "dojo/store/Memory",
  27. "dojo/data/ObjectStore",
  28. "dijit/_TemplatedMixin",
  29. "dijit/_WidgetsInTemplateMixin",
  30. "dijit/layout/BorderContainer",
  31. "dijit/layout/TabContainer",
  32. "dijit/layout/ContentPane",
  33. "dijit/Toolbar",
  34. "dijit/TooltipDialog",
  35. "dijit/form/Form",
  36. "dijit/form/SimpleTextarea",
  37. "dijit/form/TextBox",
  38. "dijit/form/Button",
  39. "dijit/form/DropDownButton",
  40. "dijit/TitlePane",
  41. "dijit/registry",
  42. "hpcc/_TabContainerWidget",
  43. "hpcc/ResultWidget",
  44. "hpcc/ECLSourceWidget",
  45. "hpcc/FilePartsWidget",
  46. "hpcc/WUDetailsWidget",
  47. "hpcc/DFUWUDetailsWidget",
  48. "hpcc/TargetSelectWidget",
  49. "hpcc/ESPLogicalFile",
  50. "dojo/text!../templates/SFDetailsWidget.html",
  51. "dojox/grid/EnhancedGrid",
  52. "dojox/grid/enhanced/plugins/Pagination",
  53. "dojox/grid/enhanced/plugins/IndirectSelection",
  54. "dijit/TooltipDialog"
  55. ], function (exports, declare, lang, arrayUtil, dom, domAttr, domClass, domForm, query, Memory, ObjectStore,
  56. _TemplatedMixin, _WidgetsInTemplateMixin, BorderContainer, TabContainer, ContentPane, Toolbar, TooltipDialog, Form, SimpleTextarea, TextBox, Button, DropDownButton, TitlePane, registry,
  57. _TabContainerWidget, ResultWidget, EclSourceWidget, FilePartsWidget, WUDetailsWidget, DFUWUDetailsWidget, TargetSelectWidget,
  58. ESPLogicalFile,
  59. template) {
  60. exports.fixCircularDependency = declare("SFDetailsWidget", [_TabContainerWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  61. templateString: template,
  62. baseClass: "SFDetailsWidget",
  63. borderContainer: null,
  64. tabContainer: null,
  65. summaryWidget: null,
  66. subfilesGrid: null,
  67. logicalFile: null,
  68. prevState: "",
  69. initalized: false,
  70. postCreate: function (args) {
  71. this.inherited(arguments);
  72. this.summaryWidget = registry.byId(this.id + "_Summary");
  73. this.subfilesGrid = registry.byId(this.id + "SubfilesGrid");
  74. },
  75. startup: function (args) {
  76. this.inherited(arguments);
  77. this.initSubfilesGrid();
  78. },
  79. // Hitched actions ---
  80. _onRefresh: function (event) {
  81. this.logicalFile.refresh();
  82. },
  83. _onSave: function (event) {
  84. var context = this;
  85. this.logicalFile.save(dom.byId(context.id + "Description").value);
  86. },
  87. _onDelete: function (event) {
  88. if (confirm('Delete Superfile?')) {
  89. this.logicalFile.removeSubfiles(this.subfilesGrid.store.objectStore.data, true);
  90. }
  91. },
  92. _onRemove: function (event) {
  93. this.logicalFile.removeSubfiles(this.subfilesGrid.selection.getSelected());
  94. },
  95. _onCopyOk: function (event) {
  96. this.logicalFile.copy({
  97. request: domForm.toObject(this.id + "CopyDialog")
  98. });
  99. registry.byId(this.id + "CopyDropDown").closeDropDown();
  100. },
  101. _onCopyCancel: function (event) {
  102. registry.byId(this.id + "CopyDropDown").closeDropDown();
  103. },
  104. _onDesprayOk: function (event) {
  105. this.logicalFile.despray({
  106. request: domForm.toObject(this.id + "DesprayDialog")
  107. });
  108. registry.byId(this.id + "DesprayDropDown").closeDropDown();
  109. },
  110. _onDesprayCancel: function (event) {
  111. registry.byId(this.id + "DesprayDropDown").closeDropDown();
  112. },
  113. _onRenameOk: function (event) {
  114. this.logicalFile.rename({
  115. request: domForm.toObject(this.id + "RenameDialog")
  116. });
  117. registry.byId(this.id + "RenameDropDown").closeDropDown();
  118. },
  119. _onRenameCancel: function (event) {
  120. registry.byId(this.id + "RenameDropDown").closeDropDown();
  121. },
  122. // Implementation ---
  123. init: function (params) {
  124. if (this.initalized)
  125. return;
  126. this.initalized = true;
  127. var context = this;
  128. if (params.Name) {
  129. this.logicalFile = ESPLogicalFile.Get(params.Name);
  130. this.logicalFile.watch(function (name, oldValue, newValue) {
  131. context.updateInput(name, oldValue, newValue);
  132. });
  133. this.logicalFile.refresh();
  134. }
  135. this.selectChild(this.summaryWidget, true);
  136. this.subfilesGrid.startup();
  137. },
  138. initSubfilesGrid: function () {
  139. this.subfilesGrid.setStructure([
  140. {
  141. name: "C",
  142. field: "isZipfile",
  143. width: "16px",
  144. formatter: function (compressed) {
  145. if (compressed == true) {
  146. return "C";
  147. }
  148. return "";
  149. }
  150. },
  151. {
  152. name: "K",
  153. field: "IsKeyFile",
  154. width: "16px",
  155. formatter: function (keyfile) {
  156. if (keyfile == true) {
  157. return "K";
  158. }
  159. return "";
  160. }
  161. },
  162. {
  163. name: "S",
  164. field: "isSuperfile",
  165. width: "16px",
  166. formatter: function (superfile) {
  167. if (superfile == true) {
  168. return "S";
  169. }
  170. return "";
  171. }
  172. },
  173. { name: "Logical Name", field: "Name", width: "32" },
  174. { name: "Owner", field: "Owner", width: "8" },
  175. { name: "Description", field: "Description", width: "12" },
  176. { name: "Cluster", field: "ClusterName", width: "12" },
  177. { name: "Records", field: "RecordCount", width: "8" },
  178. { name: "Size", field: "Totalsize", width: "8" },
  179. { name: "Parts", field: "Parts", width: "4" },
  180. { name: "Modified (UTC/GMT)", field: "Modified", width: "12" }
  181. ]);
  182. /*
  183. var objStore = ESPLogicalFile.CreateLFQueryObjectStore();
  184. this.subfilesGrid.setStore(objStore);
  185. this.subfilesGrid.setQuery(this.getFilter());
  186. var context = this;
  187. this.subfilesGrid.on("RowDblClick", function (evt) {
  188. if (context.onRowDblClick) {
  189. var idx = evt.rowIndex;
  190. var item = this.getItem(idx);
  191. context.onRowDblClick(item);
  192. }
  193. }, true);
  194. dojo.connect(this.subfilesGrid.selection, 'onSelected', function (idx) {
  195. context.refreshActionState();
  196. });
  197. dojo.connect(this.subfilesGrid.selection, 'onDeselected', function (idx) {
  198. context.refreshActionState();
  199. });
  200. */
  201. this.subfilesGrid.startup();
  202. },
  203. initTab: function () {
  204. var currSel = this.getSelectedChild();
  205. },
  206. showMessage: function (msg) {
  207. },
  208. updateInput: function (name, oldValue, newValue) {
  209. var domElem = dom.byId(this.id + name);
  210. if (domElem) {
  211. switch(domElem.tagName) {
  212. case "SPAN":
  213. case "DIV":
  214. domAttr.set(this.id + name, "innerHTML", newValue)
  215. break;
  216. case "INPUT":
  217. case "TEXTAREA":
  218. domAttr.set(this.id + name, "value", newValue)
  219. break;
  220. default:
  221. alert(domElem.tagName);
  222. }
  223. }
  224. if (name === "subfiles") {
  225. var data = [];
  226. arrayUtil.forEach(newValue.Item, function (item, idx) {
  227. data.push(ESPLogicalFile.Get(item));
  228. });
  229. this.subfilesGrid.rowSelectCell.toggleAllSelection(false);
  230. var dataStore = new ObjectStore({ objectStore: new Memory({ data: data }) });
  231. this.subfilesGrid.setStore(dataStore);
  232. this.subfilesGrid.setQuery({
  233. Name: "*"
  234. });
  235. }
  236. }
  237. });
  238. });