SFDetailsWidget.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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/store/Observable",
  28. "dijit/layout/BorderContainer",
  29. "dijit/layout/TabContainer",
  30. "dijit/layout/ContentPane",
  31. "dijit/Toolbar",
  32. "dijit/TooltipDialog",
  33. "dijit/form/Form",
  34. "dijit/form/SimpleTextarea",
  35. "dijit/form/TextBox",
  36. "dijit/form/Button",
  37. "dijit/form/DropDownButton",
  38. "dijit/TitlePane",
  39. "dijit/registry",
  40. "dgrid/OnDemandGrid",
  41. "dgrid/Keyboard",
  42. "dgrid/Selection",
  43. "dgrid/selector",
  44. "dgrid/extensions/ColumnResizer",
  45. "dgrid/extensions/DijitRegistry",
  46. "hpcc/_TabContainerWidget",
  47. "hpcc/ResultWidget",
  48. "hpcc/ECLSourceWidget",
  49. "hpcc/FilePartsWidget",
  50. "hpcc/WUDetailsWidget",
  51. "hpcc/DFUWUDetailsWidget",
  52. "hpcc/TargetSelectWidget",
  53. "hpcc/ESPUtil",
  54. "hpcc/ESPLogicalFile",
  55. "dojo/text!../templates/SFDetailsWidget.html",
  56. "dijit/TooltipDialog"
  57. ], function (exports, declare, lang, arrayUtil, dom, domAttr, domClass, domForm, query, Memory, Observable,
  58. BorderContainer, TabContainer, ContentPane, Toolbar, TooltipDialog, Form, SimpleTextarea, TextBox, Button, DropDownButton, TitlePane, registry,
  59. OnDemandGrid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry,
  60. _TabContainerWidget, ResultWidget, EclSourceWidget, FilePartsWidget, WUDetailsWidget, DFUWUDetailsWidget, TargetSelectWidget,
  61. ESPUtil, ESPLogicalFile,
  62. template) {
  63. exports.fixCircularDependency = declare("SFDetailsWidget", [_TabContainerWidget], {
  64. templateString: template,
  65. baseClass: "SFDetailsWidget",
  66. borderContainer: null,
  67. tabContainer: null,
  68. summaryWidget: null,
  69. subfilesGrid: null,
  70. logicalFile: null,
  71. prevState: "",
  72. postCreate: function (args) {
  73. this.inherited(arguments);
  74. this.summaryWidget = registry.byId(this.id + "_Summary");
  75. },
  76. startup: function (args) {
  77. this.inherited(arguments);
  78. this.initSubfilesGrid();
  79. },
  80. // Hitched actions ---
  81. _onRefresh: function (event) {
  82. this.logicalFile.refresh();
  83. },
  84. _onSave: function (event) {
  85. var context = this;
  86. this.logicalFile.save(dom.byId(context.id + "Description").value);
  87. },
  88. _onDelete: function (event) {
  89. if (confirm('Delete Superfile?')) {
  90. this.logicalFile.removeSubfiles(this.subfilesGrid.store.objectStore.data, true);
  91. }
  92. },
  93. _onRemove: function (event) {
  94. this.logicalFile.removeSubfiles(this.subfilesGrid.getSelected());
  95. },
  96. _onCopyOk: function (event) {
  97. this.logicalFile.copy({
  98. request: domForm.toObject(this.id + "CopyDialog")
  99. });
  100. registry.byId(this.id + "CopyDropDown").closeDropDown();
  101. },
  102. _onCopyCancel: function (event) {
  103. registry.byId(this.id + "CopyDropDown").closeDropDown();
  104. },
  105. _onDesprayOk: function (event) {
  106. this.logicalFile.despray({
  107. request: domForm.toObject(this.id + "DesprayDialog")
  108. });
  109. registry.byId(this.id + "DesprayDropDown").closeDropDown();
  110. },
  111. _onDesprayCancel: function (event) {
  112. registry.byId(this.id + "DesprayDropDown").closeDropDown();
  113. },
  114. _onRenameOk: function (event) {
  115. this.logicalFile.rename({
  116. request: domForm.toObject(this.id + "RenameDialog")
  117. });
  118. registry.byId(this.id + "RenameDropDown").closeDropDown();
  119. },
  120. _onRenameCancel: function (event) {
  121. registry.byId(this.id + "RenameDropDown").closeDropDown();
  122. },
  123. // Implementation ---
  124. init: function (params) {
  125. if (this.inherited(arguments))
  126. return;
  127. var context = this;
  128. if (params.Name) {
  129. this.logicalFile = ESPLogicalFile.Get(params.Name);
  130. var data = this.logicalFile.getData();
  131. for (key in data) {
  132. this.updateInput(key, null, data[key]);
  133. }
  134. this.logicalFile.watch(function (name, oldValue, newValue) {
  135. context.updateInput(name, oldValue, newValue);
  136. });
  137. this.logicalFile.refresh();
  138. }
  139. this.selectChild(this.summaryWidget, true);
  140. this.subfilesGrid.startup();
  141. },
  142. initSubfilesGrid: function () {
  143. var store = new Memory({
  144. idProperty: "Name",
  145. data: []
  146. });
  147. this.subfilesStore = Observable(store);
  148. this.subfilesGrid = new declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
  149. allowSelectAll: true,
  150. columns: {
  151. sel: selector({
  152. width: 27,
  153. selectorType: 'checkbox'
  154. }),
  155. isZipfile: {
  156. label: "C", width: 16, sortable: false,
  157. formatter: function (compressed) {
  158. if (compressed == true) {
  159. return "C";
  160. }
  161. return "";
  162. }
  163. },
  164. IsKeyFile: {
  165. label: "K", width: 16, sortable: false,
  166. formatter: function (keyfile) {
  167. if (keyfile == true) {
  168. return "K";
  169. }
  170. return "";
  171. }
  172. },
  173. isSuperfile: {
  174. label: "S", width: 16, sortable: false,
  175. formatter: function (superfile) {
  176. if (superfile == true) {
  177. return "S";
  178. }
  179. return "";
  180. }
  181. },
  182. Name: { label: "Logical Name" },
  183. Owner: { label: "Owner", width: 72 },
  184. Description: { label: "Description", width: 153 },
  185. ClusterName: { label: "Cluster", width: 108 },
  186. RecordCount: { label: "Records", width: 72, sortable: false },
  187. Totalsize: { label: "Size", width: 72, sortable: false },
  188. Parts: { label: "Parts", width: 45, sortable: false },
  189. Modified: { label: "Modified (UTC/GMT)", width: 155, sortable: false }
  190. },
  191. store: this.subfilesStore
  192. }, this.id + "SubfilesGrid");
  193. this.subfilesGrid.startup();
  194. },
  195. initTab: function () {
  196. var currSel = this.getSelectedChild();
  197. },
  198. showMessage: function (msg) {
  199. },
  200. updateInput: function (name, oldValue, newValue) {
  201. var registryNode = registry.byId(this.id + name);
  202. if (registryNode) {
  203. registryNode.set("value", newValue);
  204. } else {
  205. var domElem = dom.byId(this.id + name);
  206. if (domElem) {
  207. switch (domElem.tagName) {
  208. case "SPAN":
  209. case "DIV":
  210. domAttr.set(this.id + name, "innerHTML", newValue);
  211. break;
  212. case "INPUT":
  213. case "TEXTAREA":
  214. domAttr.set(this.id + name, "value", newValue);
  215. break;
  216. default:
  217. alert(domElem.tagName);
  218. }
  219. }
  220. }
  221. if (name === "subfiles") {
  222. var data = [];
  223. arrayUtil.forEach(newValue.Item, function (item, idx) {
  224. data.push(ESPLogicalFile.Get(item));
  225. });
  226. this.subfilesStore.setData(data);
  227. this.subfilesGrid.refresh();
  228. }
  229. }
  230. });
  231. });