Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.26 KB | None | 0 0
  1. @helper ShowTree(List<FileCabinetContentObject> nodes, double leftPadding)
  2. {
  3. foreach (var node in nodes.OrderBy(n => n.Ordering))
  4. {
  5. <div class="fc-content-obj fc-section">
  6. <div class="fc-obj-header">
  7. <span style="padding-left:@(leftPadding)em;">
  8. <span id="nodeIcon@(node.Id)" data-filecount="@(node.FileCount)" data-nodetype="@(node.ObjectType)">
  9. @switch (node.ObjectType)
  10. {
  11. case Enumerations.SysObjectType.FileCabinetSection:
  12. if (node.FileCount > 0)
  13. {
  14. <span class="node-icon">
  15. <img src="~/Content/img/icons/dot-blue.png" height="12" width="12" />
  16. </span>
  17. }
  18. else
  19. {
  20. <span class="node-icon">
  21. <img src="~/Content/img/icons/dot-gray.png" height="12" width="12" />
  22. </span>
  23. }
  24. break;
  25. case Enumerations.SysObjectType.FileCabinetFolder:
  26. if (node.FileCount > 0)
  27. {
  28. <span class="node-icon">
  29. <img src="~/Content/img/icons/folder-closed-blue.png" height="12" width="14" />
  30. </span>
  31. }
  32. else
  33. {
  34. <span class="node-icon">
  35. <img src="~/Content/img/icons/folder-closed-gray.png" height="12" width="14" />
  36. </span>
  37. }
  38. break;
  39. }
  40. </span>
  41. @node.Name
  42. </span>
  43. @if (node.ObjectType != Enumerations.SysObjectType.FileCabinetDocument &&
  44. node.ObjectType != Enumerations.SysObjectType.FileCabinetLinkedRequirement)
  45. {
  46. <span class="filecount">@node.FileCount files</span>
  47. }
  48.  
  49. <select id="nodeOptions@(node.Id)" data-id="@(node.Id)" data-name="@(node.Name)" data-desc="@(node.Description)" class="options">
  50. <option value="0">Options</option>
  51. <option value="1">Properties</option>
  52. @if (node.ObjectType == Enumerations.SysObjectType.FileCabinetSection ||
  53. node.ObjectType == Enumerations.SysObjectType.FileCabinetFolder)
  54. {
  55. <option value="2">New Folder</option>
  56. if (node.ObjectType == Enumerations.SysObjectType.FileCabinetFolder)
  57. {
  58. <option value="3">New Item</option>
  59. }
  60. }
  61. else if (node.ObjectType == Enumerations.SysObjectType.FileCabinetItem)
  62. {
  63. <option value="4">Upload</option>
  64. }
  65. else if (node.ObjectType == Enumerations.SysObjectType.FileCabinetDocument ||
  66. node.ObjectType == Enumerations.SysObjectType.FileCabinetLinkedRequirement)
  67. {
  68. <option value="5">Download</option>
  69. }
  70. <option value="6">Delete</option>
  71. </select>
  72.  
  73. @if (node.Children.Count > 0)
  74. {
  75. <span class="expando" data-id="@node.Id" data-collapsed="yes" style="padding-right:0.5em">@Html.Partial("icon-partials/_icon-right")</span>
  76. }
  77. </div>
  78. </div>
  79. <div class="subtree" data-parentid="@node.Id" hidden>
  80. @ShowTree(node.Children, leftPadding + 1.5)
  81. </div>
  82. }
  83. }
  84.  
  85. @section Scripts {
  86. <script>
  87. var arrowRight = $("#arrowRight").html();
  88. var arrowDown = $("#arrowDown").html();
  89. var iconFolderOpenBlue = $("#iconFolderOpenBlue").html();
  90. var iconFolderClosedBlue = $("#iconFolderClosedBlue").html();
  91. var iconFolderOpenGray = $("#iconFolderOpenGray").html();
  92. var iconFolderClosedGray = $("#iconFolderClosedGray").html();
  93.  
  94. $(document).ready(function (e) {
  95. $('.expando').on("click", function (e) {
  96. var nodeId = $(this).data("id");
  97. var collapsed = $(this).attr("data-collapsed");
  98. var icon = $("#nodeIcon" + nodeId);
  99.  
  100. if (icon.data("nodetype") == "@(Enumerations.SysObjectType.FileCabinetFolder.ToString())") {
  101. if (icon.data("filecount") > 0) {
  102. if (collapsed == "yes")
  103. icon.html(iconFolderOpenBlue);
  104. else
  105. icon.html(iconFolderClosedBlue);
  106. }
  107. else {
  108. if (collapsed == "yes")
  109. icon.html(iconFolderOpenGray);
  110. else
  111. icon.html(iconFolderClosedGray);
  112. }
  113. }
  114.  
  115. if (collapsed == "no") {
  116. $(this).html(arrowRight);
  117. $("div[data-parentid='" + nodeId + "'").attr("hidden", true);
  118. $(this).attr("data-collapsed", "yes");
  119. }
  120. else {
  121. $(this).html(arrowDown);
  122. $("div[data-parentid='" + nodeId + "'").attr("hidden", false);
  123. $(this).attr("data-collapsed", "no");
  124. }
  125. });
  126.  
  127. ExpandNodes("@Model.ExpandedNodes");
  128. });
  129.  
  130. function ExpandNodes(nodesToExpand) {
  131. var nodeIdArray = nodesToExpand.split(",");
  132.  
  133. nodeIdArray.forEach(function (nodeId) {
  134. var node = $(".expando[data-id='" + nodeId + "']")[0];
  135. //$(node).attr("data-collapsed", "no");
  136. $(node).click();
  137. });
  138. }
  139.  
  140. $('.options').on("change", function (e) {
  141. var selectedOption = $("option:selected", this).text();
  142. var nodeId = $(this).data("id");
  143. switch (selectedOption) {
  144. case "Properties":
  145. $("#modal-file-cabinet-object-title").html("Properties");
  146. $("#modal-file-cabinet-object-save").attr("data-modaltype", "properties");
  147. $("#modal-fco-name").val($(this).data("name"));
  148. $("#modal-fco-desc").val($(this).data("desc"));
  149. break;
  150. case "New Folder":
  151. $("#modal-file-cabinet-object-title").html("New Folder");
  152. $("#modal-file-cabinet-object-save").attr("data-modaltype", "newfolder");
  153. $("#modal-file-cabinet-object-save").attr("data-id", $(this).data("id"));
  154. $("#modal-fco-name").val("");
  155. $("#modal-fco-desc").val("");
  156. break;
  157. }
  158.  
  159. $("#modal-file-cabinet-object").modal("show");
  160. $(this).val(0);
  161. });
  162.  
  163. $("#modal-file-cabinet-object-cancel").on("click", function (e) {
  164. $("#modal-file-cabinet-object").modal("hide");
  165. });
  166.  
  167. $("#modal-file-cabinet-object-save").on("click", function (e) {
  168. switch ($(this).attr("data-modaltype")) {
  169. case "properties":
  170. break;
  171. case "newfolder":
  172. $.ajax({
  173. type: "POST",
  174. url: '/FileCabinet/CreateFileCabinetObject',
  175. data: {
  176. Name: $("#modal-fco-name").val(),
  177. Description: $("#modal-fco-desc").val(),
  178. ParentObjectId: $(this).data("id"),
  179. ObjectType: @((int)Enumerations.SysObjectType.FileCabinetFolder)
  180. },
  181. success: function (data) {
  182. window.location.assign("@Url.Action("Content", "FileCabinet")?id=" + @Model.Cabinet.Id + "&expandedNodes=" + BuildExpandedNodesString());
  183. }
  184. });
  185. break;
  186. }
  187. });
  188.  
  189. //Builds a comma-delimited string containing the IDs of all the expanded nodes (will be sent to and returned from server to re-expand on page refresh)
  190. function BuildExpandedNodesString() {
  191. var nodesArray = [];
  192. var expandedNodes = $(".expando[data-collapsed='no']");
  193.  
  194. $.each(expandedNodes, function (index, node) {
  195. nodesArray.push($(node).attr("data-id"));
  196. });
  197.  
  198. return nodesArray.join(",");
  199. }
  200.  
  201. function FileCabinetObjectPropertiesViewModel() {
  202. var self = this;
  203. self.editingItem = ko.observable();
  204. self.parentOfItem;
  205.  
  206. self.ShowFor = function (item, parent) {
  207. self.editingItem(item);
  208. self.parentOfItem = parent;
  209. $('#modal-file-cabinet-object').modal('show');
  210. };
  211.  
  212. self.btnSave = function () {
  213. if (self.editingItem().Id() < 1) {
  214. //TODO depperson actually call the DB
  215. self.editingItem().Id(Math.round(Math.random()*10000));
  216. self.parentOfItem.push(self.editingItem());
  217. $('#modal-file-cabinet-object').modal('hide');
  218. } else {
  219. //TODO depperson actually call the DB
  220. $('#modal-file-cabinet-object').modal('hide');
  221. }
  222. };
  223.  
  224. self.btnCancel = function () {
  225. $('#modal-file-cabinet-object').modal('hide');
  226. };
  227. }
  228. </script>
  229. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement