SFDetailsWidget.js 9.3 KB

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