PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/SAC_Dropdown_CW/muselection_search.js

https://gitlab.com/Daniel-Bessa/dev-vm
JavaScript | 325 lines | 210 code | 93 blank | 22 comment | 22 complexity | dc65d26572d723eae4296ff56c7a362d MD5 | raw file
  1. (function () {
  2. let _shadowRoot;
  3. let div;
  4. let widgetName;
  5. let _unit;
  6. var Ar = [];
  7. /*--------------------------------------------------------------------------------------------------------------- */
  8. /*-------------------------- Start: Template Creation ------------------------------------- */
  9. let tmpl = document.createElement("template");
  10. tmpl.innerHTML = `
  11. `;
  12. /*-------------------------- End: Template Creation ------------------------------------- */
  13. /*--------------------------------------------------------------------------------------------------------------- */
  14. /*--------------------------------------------------------------------------------------------------------------- */
  15. /*--------------------------Start: Main Class ------------------------------------- */
  16. class MultiInput extends HTMLElement {
  17. constructor() {
  18. super();
  19. _shadowRoot = this.attachShadow({
  20. mode: "open"
  21. });
  22. _shadowRoot.appendChild(tmpl.content.cloneNode(true));
  23. this._export_settings = {};
  24. this.addEventListener("click", event => {
  25. var eventclick = new Event("onClick");
  26. this.dispatchEvent(eventclick);
  27. console.log('click');
  28. });
  29. this._firstConnection = 0;
  30. }
  31. disconnectedCallback() {
  32. if (this._subscription) { // react store subscription
  33. this._subscription();
  34. this._subscription = null;
  35. }
  36. }
  37. onCustomWidgetBeforeUpdate(changedProperties) {
  38. if ("designMode" in changedProperties) {
  39. this._designMode = changedProperties["designMode"];
  40. }
  41. }
  42. onCustomWidgetAfterUpdate(changedProperties) {
  43. var that = this;
  44. loadthis(that, changedProperties);
  45. }
  46. _firePropertiesChanged() {
  47. this.unit = "";
  48. this.dispatchEvent(new CustomEvent("propertiesChanged", {
  49. detail: {
  50. properties: {
  51. unit: this.unit
  52. }
  53. }
  54. }));
  55. }
  56. get unit() {
  57. return this._export_settings.unit;
  58. }
  59. set unit(value) {
  60. value = _unit;
  61. this._export_settings.unit = value;
  62. }
  63. get footer() {
  64. return this._export_settings.footer;
  65. }
  66. set footer(value) {
  67. this._export_settings.footer = value;
  68. }
  69. static get observedAttributes() {
  70. return [
  71. "unit",
  72. "footer"
  73. ];
  74. }
  75. }
  76. /*--------------------------------------------------------------------------------------------------------------- */
  77. /*--------------------------End: Main Class ------------------------------------- */
  78. customElements.define("com-ds-dsds-sap-sac-mu", MultiInput);
  79. function loadthis(that, changedProperties) {
  80. var that_ = that;
  81. widgetName = changedProperties.widgetName;
  82. /*--------------------------------------------------------------------------------------------------------------- */
  83. /*--------------------------Start: Data from SAC and prepare for JSON Model ------------------------------------- */
  84. /*--------------------------------------------------------------------------------------------------------------- */
  85. var rowData = changedProperties.footer;
  86. var data = [];
  87. if (rowData.length > 0) {
  88. for (var a = 0; a < rowData[0].length; a++) {
  89. var node0 = { text: rowData[0][a].Description_a5y1o06718.id };
  90. var id0 = rowData[0][a].NODEID.id;
  91. node0.nodes = [];
  92. for (var b = 0; b < rowData[1].length; b++) {
  93. if (rowData[1][b].PARENTID.id === id0) {
  94. var node1 = { text: rowData[1][b].Description_a5y1o06718.id };
  95. var id1 = rowData[1][b].NODEID.id;
  96. node1.nodes = [];
  97. for (var c = 0; c < rowData[2].length; c++) {
  98. if (rowData[2][c].PARENTID.id === id1) {
  99. var node2 = { text: rowData[2][c].Description_a5y1o06718.id };
  100. var id2 = rowData[2][c].NODEID.id;
  101. node2.nodes = [];
  102. for (var d = 0; d < rowData[3].length; d++) {
  103. if (rowData[3][d].PARENTID.id === id2) {
  104. var node3 = { text: rowData[3][d].Description_a5y1o06718.id };
  105. var id3 = rowData[3][d].NODEID.id;
  106. node3.nodes = [];
  107. for (var e = 0; e < rowData[4].length; e++) {
  108. if (rowData[4][e].PARENTID.id === id3) {
  109. var node4 = { text: rowData[4][e].Description_a5y1o06718.id };
  110. var id4 = rowData[4][e].NODEID.id;
  111. node4.nodes = [];
  112. for (var f = 0; f < rowData[5].length; f++) {
  113. if (rowData[5][f].PARENTID.id === id4) {
  114. var node5 = { text: rowData[5][f].Description_a5y1o06718.id };
  115. var id5 = rowData[5][f].NODEID.id;
  116. node5.nodes = [];
  117. for (var g = 0; g < rowData[6].length; g++) {
  118. if (rowData[6][g].PARENTID.id === id5) {
  119. var node6 = { text: rowData[6][g].Description_a5y1o06718.id };
  120. var id6 = rowData[6][g].NODEID.id;
  121. node6.nodes = [];
  122. for (var h = 0; h < rowData[7].length; h++) {
  123. if (rowData[7][h].PARENTID.id === id6) {
  124. var node7 = { text: rowData[7][h].Description_a5y1o06718.id };
  125. var id7 = rowData[7][h].NODEID.id;
  126. node7.nodes = [];
  127. node6.nodes.push(node7);
  128. }
  129. }
  130. node5.nodes.push(node6);
  131. }
  132. }
  133. node4.nodes.push(node5);
  134. }
  135. }
  136. node3.nodes.push(node4);
  137. }
  138. }
  139. node2.nodes.push(node3);
  140. }
  141. }
  142. node1.nodes.push(node2);
  143. }
  144. }
  145. node0.nodes.push(node1);
  146. }
  147. }
  148. data.push(node0);
  149. }
  150. console.log(data);
  151. }
  152. /*--------------------------------------------------------------------------------------------------------------- */
  153. /*--------------------------End: Data from SAC and prepare for JSON Model ------------------------------------- */
  154. /*--------------------------------------------------------------------------------------------------------------- */
  155. div = document.createElement('div');
  156. // div.setAttribute("style", "position:fixed;");
  157. div.slot = "content_" + widgetName;
  158. let div0 = document.createElement('div');
  159. // Custom Tree Selection
  160. div0.innerHTML = '<script id="oView' + widgetName + '" name="oView' + widgetName + '" type="sapui5/xmlview"><mvc:View controllerName="myView.Template" xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"><SearchField width="auto" value="{search>/query}" liveChange=".onLiveChange" /><Tree id="Tree" items="{Multiinput_1>/}" mode="SingleSelectLeft" selectionChange="onSelect" includeItemInSelection="true"><headerToolbar><Toolbar><content><Title text="Brand Hierarchy" level="H2" /><ToolbarSpacer /><Select selectedKey="SingleSelect" change="handleSelectChange"><items><core:Item key="SingleSelectLeft" text="Single Selection" /><core:Item key="MultiSelect" text="Multi Selection" /></items></Select></content></Toolbar></headerToolbar><StandardTreeItem title="{' + widgetName + '>text}"/></Tree></mvc:View></script>'
  161. _shadowRoot.appendChild(div0);
  162. if (that._firstConnection === 1) {
  163. } else {
  164. let div2 = document.createElement('div');
  165. div2.innerHTML = '<div style="max-height: 580px; overflow-y: auto;" id="ui5_content_' + widgetName + '" name="ui5_content_' + widgetName + '"><slot name="content_' + widgetName + '"> </slot></div>';
  166. _shadowRoot.appendChild(div2);
  167. that._firstConnection = 1;
  168. }
  169. that_.appendChild(div);
  170. var mapcanvas_divstr = _shadowRoot.getElementById('oView' + widgetName);
  171. console.log("[MAPCANVAS]", mapcanvas_divstr);
  172. Ar.push({
  173. 'id': widgetName,
  174. 'div': mapcanvas_divstr
  175. });
  176. sap.ui.getCore().attachInit(function () {
  177. "use strict";
  178. //### Controller ###
  179. sap.ui.define(['sap/ui/core/mvc/Controller',
  180. 'sap/ui/model/json/JSONModel'],
  181. function (Controller, JSONModel) {
  182. "use strict";
  183. var PageController = Controller.extend("myView.Template", {
  184. onInit: function () {
  185. console.log(that._export_settings.footer);
  186. // set explored app's demo model on this sample
  187. var oModel = new JSONModel(data);
  188. console.log(oModel);
  189. // this.getView().setModel(oModel, that.widgetName);
  190. sap.ui.getCore().setModel(oModel, that.widgetName);
  191. },
  192. onSelect: function (oEvent) {
  193. var listselected = ''
  194. for (var i = 0; i < this.getView().byId("Tree").getSelectedItems().length; i++) {
  195. listselected += this.getView().byId("Tree").getSelectedItems()[i].getBindingContext("Multiinput_1").getObject().text + ","
  196. }
  197. console.log(listselected);
  198. _unit = listselected;
  199. // new sap.m.MessageToast.show(_unit)
  200. that._firePropertiesChanged();
  201. // console.log(unit);
  202. },
  203. onLiveChange: function(event) {
  204. const query = event.getParameter("newValue").trim();
  205. this.byId("Tree").getBinding("items").filter(query ? new sap.ui.model.Filter({
  206. path: "text",
  207. operator: "Contains",
  208. value1: query,
  209. }) : null);
  210. this.byId("Tree").expandToLevel(9999);
  211. },
  212. handleSelectChange: function (oEvent) {
  213. var mode = oEvent.getParameter("selectedItem").getKey();
  214. this.byId("Tree").setMode(mode);
  215. console.log(mode);
  216. }
  217. });
  218. return PageController;
  219. });
  220. console.log("widgetName Final:" + Ar[0]);
  221. var foundIndex = Ar.findIndex(x => x.id == widgetName);
  222. console.log("[FOUND INDEX]", foundIndex, Ar[foundIndex]);
  223. var divfinal = Ar[foundIndex].div;
  224. console.log(divfinal);
  225. //### THE APP: place the XMLView somewhere into DOM ###
  226. var oView = sap.ui.xmlview({
  227. viewContent: jQuery(divfinal).html(),
  228. });
  229. oView.placeAt(div);
  230. });
  231. }
  232. })();