SFDetailsWidget.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. legacyPane: null,
  67. legacyPaneLoaded: false,
  68. subfilesGrid: null,
  69. logicalFile: null,
  70. prevState: "",
  71. initalized: false,
  72. postCreate: function (args) {
  73. this.inherited(arguments);
  74. this.summaryWidget = registry.byId(this.id + "_Summary");
  75. this.legacyPane = registry.byId(this.id + "_Legacy");
  76. this.subfilesGrid = registry.byId(this.id + "SubfilesGrid");
  77. },
  78. startup: function (args) {
  79. this.inherited(arguments);
  80. this.initSubfilesGrid();
  81. },
  82. // Hitched actions ---
  83. _onRefresh: function (event) {
  84. this.logicalFile.refresh();
  85. },
  86. _onSave: function (event) {
  87. var context = this;
  88. this.logicalFile.save(dom.byId(context.id + "Description").value);
  89. },
  90. _onDelete: function (event) {
  91. if (confirm('Delete Superfile?')) {
  92. this.logicalFile.removeSubfiles(this.subfilesGrid.store.objectStore.data, true);
  93. }
  94. },
  95. _onRemove: function (event) {
  96. this.logicalFile.removeSubfiles(this.subfilesGrid.selection.getSelected());
  97. },
  98. _onCopyOk: function (event) {
  99. this.logicalFile.copy({
  100. request: domForm.toObject(this.id + "CopyDialog")
  101. });
  102. registry.byId(this.id + "CopyDropDown").closeDropDown();
  103. },
  104. _onCopyCancel: function (event) {
  105. registry.byId(this.id + "CopyDropDown").closeDropDown();
  106. },
  107. _onDesprayOk: function (event) {
  108. this.logicalFile.despray({
  109. request: domForm.toObject(this.id + "DesprayDialog")
  110. });
  111. registry.byId(this.id + "DesprayDropDown").closeDropDown();
  112. },
  113. _onDesprayCancel: function (event) {
  114. registry.byId(this.id + "DesprayDropDown").closeDropDown();
  115. },
  116. _onRenameOk: function (event) {
  117. this.logicalFile.rename({
  118. request: domForm.toObject(this.id + "RenameDialog")
  119. });
  120. registry.byId(this.id + "RenameDropDown").closeDropDown();
  121. },
  122. _onRenameCancel: function (event) {
  123. registry.byId(this.id + "RenameDropDown").closeDropDown();
  124. },
  125. // Implementation ---
  126. init: function (params) {
  127. if (this.initalized)
  128. return;
  129. this.initalized = true;
  130. var context = this;
  131. if (params.Name) {
  132. //dom.byId(this.id + "Name").innerHTML = params.Name;
  133. //dom.byId(this.id + "LogicalFileName2").value = params.Name;
  134. this.logicalFile = ESPLogicalFile.Get(params.Name);
  135. var data = this.logicalFile.getData();
  136. for (key in data) {
  137. this.updateInput(key, null, data[key]);
  138. }
  139. this.logicalFile.watch(function (name, oldValue, newValue) {
  140. context.updateInput(name, oldValue, newValue);
  141. });
  142. this.logicalFile.refresh();
  143. }
  144. this.selectChild(this.summaryWidget, true);
  145. this.subfilesGrid.startup();
  146. },
  147. initSubfilesGrid: function () {
  148. this.subfilesGrid.setStructure([
  149. {
  150. name: "C",
  151. field: "isZipfile",
  152. width: "16px",
  153. formatter: function (compressed) {
  154. if (compressed == true) {
  155. return "C";
  156. }
  157. return "";
  158. }
  159. },
  160. {
  161. name: "K",
  162. field: "IsKeyFile",
  163. width: "16px",
  164. formatter: function (keyfile) {
  165. if (keyfile == true) {
  166. return "K";
  167. }
  168. return "";
  169. }
  170. },
  171. {
  172. name: "S",
  173. field: "isSuperfile",
  174. width: "16px",
  175. formatter: function (superfile) {
  176. if (superfile == true) {
  177. return "S";
  178. }
  179. return "";
  180. }
  181. },
  182. { name: "Logical Name", field: "Name", width: "32" },
  183. { name: "Owner", field: "Owner", width: "8" },
  184. { name: "Description", field: "Description", width: "12" },
  185. { name: "Cluster", field: "ClusterName", width: "12" },
  186. { name: "Records", field: "RecordCount", width: "8" },
  187. { name: "Size", field: "Totalsize", width: "8" },
  188. { name: "Parts", field: "Parts", width: "4" },
  189. { name: "Modified (UTC/GMT)", field: "Modified", width: "12" }
  190. ]);
  191. /*
  192. var objStore = ESPLogicalFile.CreateLFQueryObjectStore();
  193. this.subfilesGrid.setStore(objStore);
  194. this.subfilesGrid.setQuery(this.getFilter());
  195. var context = this;
  196. this.subfilesGrid.on("RowDblClick", function (evt) {
  197. if (context.onRowDblClick) {
  198. var idx = evt.rowIndex;
  199. var item = this.getItem(idx);
  200. context.onRowDblClick(item);
  201. }
  202. }, true);
  203. dojo.connect(this.subfilesGrid.selection, 'onSelected', function (idx) {
  204. context.refreshActionState();
  205. });
  206. dojo.connect(this.subfilesGrid.selection, 'onDeselected', function (idx) {
  207. context.refreshActionState();
  208. });
  209. */
  210. this.subfilesGrid.startup();
  211. },
  212. initTab: function () {
  213. var currSel = this.getSelectedChild();
  214. if (currSel.id == this.legacyPane.id && !this.legacyPaneLoaded) {
  215. this.legacyPaneLoaded = true;
  216. this.legacyPane.set("content", dojo.create("iframe", {
  217. src: "/WsDfu/DFUInfo?Name=" + this.logicalFile.Name,//+ "&Cluster=" + this.logicalFile.cluster,
  218. style: "border: 0; width: 100%; height: 100%"
  219. }));
  220. }
  221. },
  222. showMessage: function (msg) {
  223. },
  224. updateInput: function (name, oldValue, newValue) {
  225. var domElem = dom.byId(this.id + name);
  226. if (domElem) {
  227. switch(domElem.tagName) {
  228. case "SPAN":
  229. case "DIV":
  230. domAttr.set(this.id + name, "innerHTML", newValue)
  231. break;
  232. case "INPUT":
  233. case "TEXTAREA":
  234. domAttr.set(this.id + name, "value", newValue)
  235. break;
  236. default:
  237. alert(domElem.tagName);
  238. }
  239. }
  240. if (name === "subfiles") {
  241. var data = [];
  242. arrayUtil.forEach(newValue.Item, function (item, idx) {
  243. data.push(ESPLogicalFile.Get(item));
  244. });
  245. this.subfilesGrid.rowSelectCell.toggleAllSelection(false);
  246. var dataStore = new ObjectStore({ objectStore: new Memory({ data: data }) });
  247. this.subfilesGrid.setStore(dataStore);
  248. this.subfilesGrid.setQuery({
  249. Name: "*"
  250. });
  251. }
  252. }
  253. });
  254. });