Advertisement
Guest User

Untitled

a guest
Feb 18th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.68 KB | None | 0 0
  1. sap.ui.define([
  2. "Controller/base.controller",
  3. "sap/ui/model/json/JSONModel",
  4. "Fragment/dialogSociety.controller",
  5. "Fragment/dialogFrontOffice.controller",
  6. "Fragment/dialogDistributor.controller",
  7. "Fragment/dialogSerhs.controller",
  8. "Fragment/dialogRole.controller",
  9. "sap/m/Dialog",
  10. "sap/m/Button",
  11. "sap/m/Text",
  12. "sap/ui/model/Filter",
  13. "sap/ui/model/FilterOperator",
  14. "Helper/constants",
  15. "Helper/formatter",
  16. "Fragment/shopping/dialogCreateOrder.controller"
  17. ], function (BaseController, JSONModel, dialogSocietyController, dialogFrontOfficeController, dialogDistributorController,
  18. dialogSerhsController,
  19. dialogRoleController, Dialog, Button,
  20. Text, Filter, FilterOperator, constants, formatter, dialogCreateOrderController) {
  21. "use strict";
  22.  
  23. return BaseController.extend("Controller.main", {
  24.  
  25. // viewName: "main",
  26.  
  27. formatter: formatter,
  28.  
  29. onInit: function () {
  30. BaseController.prototype.onInit.apply(this, arguments);
  31.  
  32. var that = this;
  33. sap.ui.getCore().getEventBus().subscribe("Main", "getUsers", this._setUsers, this);
  34. sap.ui.getCore().getEventBus().subscribe("Main", "getUsersGpv", this._setUsersGpv, this);
  35. sap.ui.getCore().getEventBus().subscribe("Main", "setRoles", this._changeRoles, this);
  36. sap.ui.getCore().getEventBus().subscribe("Main", "countCommunications", this._updateCommunicationsCounter, this);
  37. sap.ui.getCore().getEventBus().subscribe("Main", "getCommunications", this._getCommunications, this);
  38.  
  39. //declare CONTROLS
  40. this.oButtonCollapseExpand = this.byId("buttonCollapseExpand");
  41. this.oButtonCrearPedido = this.byId("buttonCrearPedido");
  42. this.oLabelUser = this.byId("labelNameUser");
  43. this.oLabelRole = this.byId("labelRoleName");
  44. this.oSideNavigation = this.byId("sideNavigation");
  45. this.oToolPage = this.byId("toolPage");
  46. this.oInfoLabelCommunications = this.byId("infoLabelCommunications");
  47.  
  48. //declare MODELS
  49. this.rolesModel = this.getComponent().getModel("rolesModel");
  50. this.userConfigModel = this.getComponent().getModel("userConfigModel");
  51. this.productsModel = this.getComponent().getModel("productsModel");
  52. this.productsAllInfoModel = this.getComponent().getModel("productsAllInfoModel");
  53. this.tiendasModel = this.getComponent().getModel("tiendasModel");
  54. this.footerLinksModel = this.getComponent().getModel("footerLinksModel");
  55. this.sectoresModel = this.getComponent().getModel("sectoresModel");
  56. this.sectoresFamiliaModel = this.getComponent().getModel("sectoresFamiliaModel");
  57.  
  58. sap.ui.getCore().getEventBus().publish("Base", "getToolPageMenu", this.oToolPage);
  59.  
  60. this.userConfigModel.attachRequestCompleted(function () {
  61. that._setUserLogged(function () {
  62. var userConfig = that.userConfigModel.getData().d.results[0];
  63. var actualUser = that.getModel("actualUsersModel").getData().user[0];
  64.  
  65. if (userConfig.P_DISTRIBUIDOR || userConfig.P_GPV || actualUser.Suplantando) {
  66. that._getTienda();
  67. that._getGestorData();
  68. that._getFiltrosEstadisticas();
  69. }
  70. });
  71. });
  72.  
  73. this.footerLinksModel.attachRequestCompleted(function () {
  74. that._setFooter();
  75. });
  76.  
  77. this._getCommunications();
  78.  
  79. // Enable to refresh communications counter
  80. setInterval(function () {
  81. sap.ui.getCore().getEventBus().publish("Main", "getCommunications");
  82. }, 240000);
  83. },
  84.  
  85. onRouteMatched: function () {},
  86.  
  87. _getTienda: function () {
  88. var that = this;
  89. var oSocietyModel = sap.ui.getCore().getModel("oSocietyModel");
  90. var actualUsersModel = this.getModel("actualUsersModel");
  91.  
  92. if (oSocietyModel !== undefined && actualUsersModel !== undefined) {
  93. var userId = actualUsersModel.getData().user[0].IdUser;
  94. var service = constants.entity.tienda + "(idusr='" + userId + "',bukrs='" + oSocietyModel.BUKRS + "',vkorg='" + oSocietyModel.VKORG +
  95. "')";
  96. var aParams = {
  97. "$expand": [constants.expand.tiendaDesc, constants.expand.tiposDoc, constants.expand.tspat]
  98. };
  99.  
  100. this.loading(true);
  101. con.Read(service, aParams, [], [], true, this, function (resp, oController) {
  102. if (!oController.checkErrorResponse(resp)) {
  103. that.tiendasModel.setData(resp);
  104. that.oButtonCrearPedido.setEnabled(true);
  105.  
  106. }
  107. that.loading(false);
  108. });
  109. }
  110. },
  111.  
  112. _getFiltrosEstadisticas: function () {
  113. var that = this;
  114. var oSocietyModel = sap.ui.getCore().getModel("oSocietyModel");
  115. var actualUsersModel = this.getModel("actualUsersModel");
  116.  
  117. if (oSocietyModel !== undefined && actualUsersModel !== undefined) {
  118. var userId = actualUsersModel.getData().user[0].IdUser;
  119. var service = constants.entity.filtrosEstadisticas + "(Kunnr='" + this.getActualUserInfo("IdUser") + "',Bukrs='" + this.getActualUserInfo(
  120. "Bukrs") + "',Vkorg='" +
  121. this.getActualUserInfo("Vkorg") +
  122. "',Vtweg='1')";
  123. var aParams = {
  124. "$expand": [constants.expand.estadisticasFilter]
  125. };
  126.  
  127. this.loading(true);
  128. con.Read(service, aParams, [], [], false, this, function (resp, oController) {
  129. if (!oController.checkErrorResponse(resp)) {
  130.  
  131. var sectores = resp.Sectores.results.filter(function (obj, pos, arr) {
  132. return arr.map(function (mapObj) {
  133. return mapObj["Spart"];
  134. }).indexOf(obj["Spart"]) === pos;
  135. });
  136.  
  137. that.sectoresModel.setData(sectores);
  138. that.sectoresFamiliaModel.setData(resp.Sectores);
  139. }
  140. that.loading(false);
  141. });
  142. }
  143. },
  144.  
  145. _getGestorData: function () {
  146. var that = this;
  147. var url = Helper.formatUrl(constants.entity.miGestor + "(Kunnr={0},Vkorg={1})", [this.getActualUserInfo("Kunnr"),
  148. this.getActualUserInfo("Vkorg")
  149. ]);
  150. this.loading(true);
  151. con.Read(url, {}, [], [], true, this, function (resp, oController) {
  152. if (!oController.checkErrorResponse(resp)) {
  153. var oModel = new JSONModel(resp);
  154. that.setModel(oModel, "gestorModel");
  155. }
  156. that.loading(false);
  157. });
  158. },
  159.  
  160. _setFooter: function () {
  161. if (this.modelWithData(this.footerLinksModel)) {
  162. var obj = {};
  163. $.each(this.footerLinksModel.getProperty("/d/results"), function (i, n) {
  164. //obj[n.Menu] = n.ObjectName;
  165. obj[n.Menu] = n;
  166. });
  167. this.setModel(new JSONModel(obj), "footerModel");
  168. }
  169. },
  170.  
  171. _setUserLogged: function (callback) {
  172. var that = this;
  173. var aParams = {
  174. "$expand": [constants.expand.sociedad]
  175. };
  176.  
  177. this.loading(true);
  178. con.Read(constants.entity.userConfig, {}, [], [], true, this, function (resp, oController) { //get data of user config
  179. if (!oController.checkErrorResponse(resp)) {
  180. if (resp.results.length === 0) {
  181. that.goTo("errorPage");
  182. } else {
  183. var user = resp.results[0];
  184.  
  185. var actualUserData = {
  186. user: [{
  187. IdUser: user.ID_USER,
  188. Name: user.NOM_USER,
  189. Solicitante: user.SOLICITANTE,
  190. Vkorg: user.VKORG,
  191. Bukrs: user.BUKRS,
  192. Suplantando: false,
  193. SYSYSID: user.SYSYSID
  194. }]
  195. };
  196. that.setModel(new JSONModel(actualUserData), "actualUsersModel");
  197.  
  198. var actualRolesData = {
  199. P_BACK_OFF: JSON.parse(user.P_BACK_OFF),
  200. P_FRONT_OFF: JSON.parse(user.P_FRONT_OFF),
  201. P_DES_COMER: JSON.parse(user.P_DES_COMER),
  202. P_DISTRIBUIDOR: JSON.parse(user.P_DISTRIBUIDOR),
  203. P_GPV: JSON.parse(user.P_GPV)
  204. };
  205. that._setHeaderText(actualRolesData);
  206. that._setRole(actualRolesData);
  207.  
  208. that._setSociety();
  209.  
  210. sap.ui.getCore().getEventBus().publish("Home", "setWelcome", actualUserData);
  211. that.refreshUserData();
  212.  
  213. // that._setVisibleControls();
  214. }
  215. } else {
  216. that.goTo("errorPage");
  217. }
  218. that.loading(false);
  219. callback();
  220. });
  221. },
  222.  
  223. _setVisibleControls: function () {
  224. if (this.getModel("actualUsersModel") !== undefined && this.getModel("actualRolesModel") !== undefined) {
  225.  
  226. var isVisibleButtonCrearPedido = this.getModel("userParamModel").getProperty(
  227. "/MisCompras/DetallePedidos/CrearModificarAnularPedido/Visualizar");
  228. var isFO = this.getModel("actualRolesModel").getProperty("/P_FRONT_OFF");
  229. var isDist = this.getModel("actualRolesModel").getProperty("/P_DISTRIBUIDOR");
  230. var isGPV = this.getModel("actualRolesModel").getProperty("/P_GPV");
  231. var isSuplantando = this.getModel("actualUsersModel").getProperty("/user/0/Suplantando");
  232. var isVisible = (isFO && isSuplantando) || isDist || (isGPV && isSuplantando);
  233.  
  234. this.oButtonCrearPedido.setVisible(isVisible);
  235.  
  236. sap.ui.getCore().getEventBus().publish("Home", "setVisibleTableProducts", {
  237. visible: isVisible
  238. });
  239. }
  240. },
  241.  
  242. _setSociety: function () { //save in Core the Societies of user
  243. if (sap.ui.getCore().getModel("oSocietyModel") === undefined) {
  244. var oSocietiesData = this.userConfigModel.getProperty("/d/results/0");
  245. sap.ui.getCore().setModel(oSocietiesData, "oSocietyModel");
  246. }
  247.  
  248. sap.ui.getCore().getEventBus().publish("Home", "addAdvertisements");
  249. sap.ui.getCore().getEventBus().publish("Home", "setFirstOrder", this.getModel("actualUsersModel"));
  250. },
  251.  
  252. _setUsers: function (sChanel, sEvent, oData) { //refresh actualUserModel with the users selected in header
  253. var oDataModel = oData;
  254.  
  255. var oModel = new JSONModel(oDataModel);
  256. this.setModel(oModel, "actualUsersModel");
  257.  
  258. var userConfig = this.userConfigModel.getData().d.results[0];
  259. var actualUser = this.getModel("actualUsersModel").getData().user[0];
  260.  
  261. this._setHeaderText();
  262. this.refreshUserData();
  263. this._setVisibleControls();
  264.  
  265. if (userConfig.P_DISTRIBUIDOR || userConfig.P_GPV || actualUser.Suplantando) {
  266. this._getClientsData();
  267. this._getTienda();
  268. this._getGestorData();
  269. this._getFiltrosEstadisticas();
  270. }
  271. },
  272.  
  273. _setUsersGpv: function (sChanel, sEvent, oData) { //refresh actualUserModel with the users selected in header
  274. var oDataModel = oData;
  275.  
  276. var oModel = new JSONModel(oDataModel);
  277. this.setModel(oModel, "actualUsersModel");
  278.  
  279. this._setHeaderText();
  280. this._setVisibleControls();
  281. },
  282.  
  283. _getClientsData: function (oEvent) {
  284. var that = this;
  285. var aParams = {
  286. "idusr": this.getModel("actualUsersModel").getData().user[0].IdUser
  287. };
  288.  
  289. this.loading(true);
  290. con.CallFunction(constants.functions.clientesSSTT, "GET", aParams, [], [], true, this, function (resp, oController) {
  291. if (!oController.checkErrorResponse(resp)) {
  292. var obj = {
  293. d: resp
  294. };
  295. var oModel = new JSONModel(obj);
  296.  
  297. that.setModel(oModel, "clientesSSTTModel");
  298. }
  299. that.loading(false);
  300. });
  301. },
  302.  
  303. _setParams: function () {
  304. var that = this;
  305.  
  306. var societyModel = sap.ui.getCore().getModel("oSocietyModel");
  307.  
  308. var aParams = {
  309. "Bukrs": societyModel.BUKRS,
  310. "User": this.getModel("actualUsersModel").getProperty("/user/0/IdUser")
  311. };
  312.  
  313. con.CallFunction(constants.functions.userParams, "GET", aParams, [], [], false, this, function (resp, oController) {
  314. if (!oController.checkErrorResponse(resp)) {
  315. if (resp.results.length === 0) {
  316. that.goTo("errorPage");
  317. } else {
  318. var oModel = new JSONModel(resp);
  319. that.getOwnerComponent().setModel(oModel, "userParamModel");
  320. that.getOwnerComponent()._prepareUserParams();
  321.  
  322. that._setVisibleControls();
  323. }
  324. } else {
  325. that.goTo("errorPage");
  326. }
  327. });
  328. },
  329.  
  330. refreshUserData: function () { //go to Home, refresh table of orders and refresh counter communications
  331. this._setParams();
  332. sap.ui.getCore().getEventBus().publish("Home", "setFirstOrder", this.getModel("actualUsersModel"));
  333. this.onGoHome();
  334. this._updateCounter();
  335. },
  336.  
  337. _changeRoles: function (sChanel, sEvent, oData) {
  338. var that = this;
  339. var oSocietyModel = sap.ui.getCore().getModel("oSocietyModel");
  340.  
  341. var aParams = {
  342. "BackOff": oData.P_BACK_OFF,
  343. "FrontOff": oData.P_FRONT_OFF,
  344. "DesComer": oData.P_DES_COMER,
  345. "Distribuidor": oData.P_DISTRIBUIDOR,
  346. "Gpv": oData.P_GPV,
  347. "Bukrs": oSocietyModel.BUKRS,
  348. "Vkorg": oSocietyModel.VKORG
  349. };
  350.  
  351. // this.loading(true);
  352. con.CallFunction(constants.functions.usersRole, "GET", aParams, [], [], false, this, function (resp, oController) {
  353. if (!oController.checkErrorResponse(resp)) {
  354. that._setRole(oData);
  355.  
  356. location.reload();
  357. }
  358. // that.loading(false);
  359. });
  360. },
  361.  
  362. _setRole: function (oData) { //save role information and set text Label
  363. var i;
  364. var sText = "";
  365. var size = 0;
  366.  
  367. for (i in oData) {
  368. if (oData[i]) {
  369. size++;
  370. }
  371. }
  372.  
  373. var count = 0;
  374. for (i in oData) {
  375.  
  376. if (oData[i]) {
  377. sText = sText + i;
  378. if (count < size - 1) {
  379. sText = sText + ", ";
  380. }
  381. count++;
  382. }
  383. }
  384.  
  385. this.oLabelRole.setText(sText);
  386.  
  387. this.setModel(new JSONModel(oData), "actualRolesModel");
  388. },
  389.  
  390. _updateCounter: function (sChanel, sEvent, oData) {
  391. this._getCommunications();
  392. },
  393.  
  394. _getCommunications: function () {
  395. var that = this;
  396. var oUsersModel = this.getModel("actualUsersModel");
  397. var oSocietyModel = sap.ui.getCore().getModel("oSocietyModel");
  398. var aFilters = [];
  399.  
  400. if (oUsersModel !== undefined) {
  401. var gestores = [];
  402.  
  403. $.each(oUsersModel.getData().user, function (i, n) {
  404. gestores.push(n.IdUser);
  405. });
  406. aFilters.push(new Filter("IdUser", FilterOperator.EQ, Helper.baseEncryptArray(gestores)));
  407. }
  408.  
  409. // Se añaden los filtros por sociedad
  410. aFilters.push(new Filter("Bukrs", FilterOperator.EQ, oSocietyModel ? oSocietyModel.BUKRS : null));
  411. aFilters.push(new Filter("Vkorg", FilterOperator.EQ, oSocietyModel ? oSocietyModel.VKORG : null));
  412.  
  413. // this.loading(true);
  414. con.Read(constants.entity.comunicados, {}, aFilters, [], true, this, function (resp, oController) { //get data of communication (only no read communications)
  415. if (!oController.checkErrorResponse(resp)) {
  416. that.setModel(new JSONModel(resp), "communicationsModel");
  417. that._updateCommunicationsCounter();
  418. }
  419. // that.loading(false);
  420. });
  421. },
  422.  
  423. _updateCommunicationsCounter: function () {
  424. if (this.getModel("communicationsModel")) {
  425. var communications = this.getModel("communicationsModel").getData().results;
  426.  
  427. if (Helper.currentMessage) {
  428. $.each(communications, function (i, n) {
  429. if (n.IdComunicado === Helper.currentMessage) {
  430. n.Leido = "true";
  431. }
  432. });
  433. delete Helper.currentMessage;
  434. }
  435.  
  436. var communicationsNoRead = $.grep(communications, function (n) {
  437. return n.Leido === "false";
  438. });
  439.  
  440. this.oInfoLabelCommunications.setVisible(communicationsNoRead.length > 0);
  441. this.oInfoLabelCommunications.setText(communicationsNoRead.length);
  442. }
  443. },
  444.  
  445. _setHeaderText: function () {
  446. if (this.getModel("actualUsersModel") !== undefined) {
  447. var oDataModel = this.getModel("actualUsersModel").getData();
  448. var sName = "";
  449.  
  450. if (oDataModel.user.length === 1) {
  451. sName = oDataModel.user[0].Name;
  452. } else {
  453. sName = this.getText('frontOfficeQtt', [oDataModel.user.length]);
  454. }
  455.  
  456. this.oLabelUser.setText(sName);
  457. this.oLabelUser.setTooltip(sName);
  458. //guardar dato en modelo global!!!
  459. }
  460. },
  461.  
  462. onResetValues: function () {
  463. this._setUserLogged(function () {});
  464. },
  465.  
  466. onOpenDialog_Role: function (oEvent) {
  467. if (this.rolesModel !== undefined) {
  468. if (!this._oDialogRole) {
  469. dialogRoleController.setRootController(this);
  470. this._oDialogRole = sap.ui.xmlfragment("Fragment.dialogRole", dialogRoleController);
  471. this.getView().addDependent(this._oDialogRole);
  472. }
  473.  
  474. this.rolesModel.setProperty("/title", this.getText("roles"));
  475. this._oDialogRole.setModel(this.rolesModel);
  476.  
  477. sap.ui.getCore().getEventBus().publish("dialogRoles", "setRoles", this.getModel("actualRolesModel").getData());
  478. this._oDialogRole.open();
  479. }
  480. },
  481.  
  482. onOpenDialog_Society: function (oEvent) {
  483. var oSocietiesData = this.userConfigModel.getProperty("/d");
  484.  
  485. if (!this._oDialogSociety) {
  486. dialogSocietyController.setRootController(this);
  487. this._oDialogSociety = sap.ui.xmlfragment("Fragment.dialogSociety", dialogSocietyController);
  488. this.getView().addDependent(this._oDialogSociety);
  489.  
  490. var oSocietyModel = new JSONModel(oSocietiesData);
  491. this._oDialogSociety.setModel(oSocietyModel);
  492. }
  493.  
  494. if (oSocietiesData.results.length > 1) {
  495. sap.ui.getCore().getEventBus().publish("dialogSociety", "setSocieties");
  496. this._oDialogSociety.open();
  497. }
  498. },
  499.  
  500. onOpenDialog_FrontOffice: function (oEvent) {
  501. var that = this;
  502.  
  503. this._getUsersFrontOffice(function (data) {
  504. that.setModel(new JSONModel(data), "usersFOModel");
  505.  
  506. if (!that._oDialogFO) {
  507. dialogFrontOfficeController.setRootController(that);
  508. that._oDialogFO = sap.ui.xmlfragment("Fragment.dialogFrontOffice", dialogFrontOfficeController);
  509. that.getView().addDependent(that._oDialogFO);
  510. }
  511.  
  512. that.getModel("usersFOModel").setProperty("/title", that.getText("frontOffice"));
  513. that._oDialogFO.setModel(that.getModel("usersFOModel"));
  514.  
  515. sap.ui.getCore().getEventBus().publish("dialogFrontOffice", "setUsersFrontOffice", that.getModel("actualUsersModel").getData());
  516.  
  517. that._oDialogFO.open();
  518. });
  519. },
  520.  
  521. _getUsersFrontOffice: function (callback) {
  522. var that = this;
  523. var oSocietyModel = sap.ui.getCore().getModel("oSocietyModel");
  524.  
  525. var aParams = {
  526. "Bukrs": oSocietyModel.BUKRS,
  527. "Vkorg": oSocietyModel.VKORG
  528. };
  529.  
  530. // this.loading(true);
  531. con.CallFunction(constants.functions.gestorSociedad, "GET", aParams, [], [], false, this, function (resp, oController) {
  532. if (!oController.checkErrorResponse(resp)) {
  533. callback(resp);
  534. }
  535. // that.loading(false);
  536. });
  537. },
  538.  
  539. onOpenDialog_Distributor: function (oEvent) {
  540. var that = this;
  541.  
  542. this._getDistributors(function (data) {
  543. if (!that._oDialogD) {
  544. dialogDistributorController.setRootController(that);
  545. that._oDialogD = sap.ui.xmlfragment("Fragment.dialogDistributor", dialogDistributorController);
  546. that.getView().addDependent(that._oDialogD);
  547. }
  548.  
  549. that.getModel("actualUsersModel").setProperty("/title", that.getText("distribuidores"));
  550. sap.ui.getCore().getEventBus().publish("dialogDistributor", "setUsersDistributor", data);
  551.  
  552. that._oDialogD.open();
  553. });
  554. },
  555.  
  556. onOpenDialog_Serhs: function (oEvent) {
  557. var that = this;
  558.  
  559. this._getDistributors(function (data) {
  560. if (!that._oDialogSerhs) {
  561. dialogSerhsController.setRootController(that);
  562. that._oDialogSerhs = sap.ui.xmlfragment("Fragment.dialogSerhs", dialogSerhsController);
  563. that.getView().addDependent(that._oDialogSerhs);
  564. }
  565.  
  566. that.getModel("actualUsersModel").setProperty("/title", that.getText("serhs"));
  567. sap.ui.getCore().getEventBus().publish("dialogSerhs", "setUsersSerhs", data);
  568.  
  569. that._oDialogSerhs.open();
  570. });
  571. },
  572.  
  573. _getDistributors: function (callback) {
  574. var that = this;
  575. var oModel = this.getModel("actualUsersModel");
  576.  
  577. if (oModel !== undefined) {
  578. var FO = oModel.getProperty("/user");
  579. var oSocietyModel = sap.ui.getCore().getModel("oSocietyModel");
  580.  
  581. var gestores = [];
  582. $.each(FO, function (i, n) {
  583. gestores.push(n.IdUser);
  584. })
  585.  
  586. var aParams = {
  587. "$expand": [constants.expand.solicitantesInterlocutores]
  588. };
  589.  
  590. var aFilters = [];
  591. aFilters.push(new Filter("Bukrs", FilterOperator.EQ, oSocietyModel.BUKRS));
  592. aFilters.push(new Filter("Vkorg", FilterOperator.EQ, oSocietyModel.VKORG));
  593. aFilters.push(new Filter("Gestores", FilterOperator.EQ, Helper.baseEncryptArray(gestores)));
  594.  
  595. this.loading(true);
  596. con.Read(constants.entity.suplantarUsuario, aParams, aFilters, [], true, this, function (resp, oController) {
  597. if (!oController.checkErrorResponse(resp)) {
  598. callback(resp);
  599. }
  600. that.loading(false);
  601. });
  602. }
  603. },
  604.  
  605. onGoTo: function (oEvent) {
  606. var sView = oEvent.getParameter("item").getKey();
  607. var that = this;
  608.  
  609. if (this._isViewForm()) {
  610. this._openDialogConfirmation("cancelForm", function () {
  611. that.goTo(sView);
  612. });
  613. } else {
  614. that.goTo(sView);
  615. }
  616. },
  617.  
  618. onGoCommunications: function () {
  619. var that = this;
  620.  
  621. if (this._isViewForm()) {
  622. this._openDialogConfirmation("cancelForm", function () {
  623. that.goTo("communications");
  624. });
  625. } else {
  626. that.goTo("communications");
  627. }
  628. },
  629.  
  630. onGoHome: function () {
  631. var that = this;
  632.  
  633. if (this._isViewForm()) {
  634. this._openDialogConfirmation("cancelForm", function () {
  635. that.goTo("home");
  636. });
  637. } else {
  638. that.goTo("home");
  639. }
  640. },
  641.  
  642. onCollapseExpandPress: function (forced) {
  643. var sideExpanded = this.oToolPage.getSideExpanded();
  644.  
  645. this.oToolPage.setSideExpanded(!sideExpanded);
  646. },
  647.  
  648. onPressShoppping: function () {
  649. var that = this;
  650.  
  651. if (this._isViewForm()) {
  652. this._openDialogConfirmation("cancelForm", function () {
  653. // that.goTo("shopping");
  654. // sap.ui.getCore().getEventBus().publish("Shopping", "onCreateOrder");
  655. that.onCreateOrder();
  656. });
  657. } else {
  658. // this.goTo("shopping");
  659. // sap.ui.getCore().getEventBus().publish("Shopping", "onCreateOrder");
  660. this.onCreateOrder();
  661. }
  662. },
  663.  
  664. onCreateOrder: function () {
  665. if (!this._oDialogCreateOrder) {
  666. this._oDialogCreateOrder = sap.ui.xmlfragment("Fragment.shopping.dialogCreateOrder", dialogCreateOrderController);
  667. this.getView().addDependent(this._oDialogCreateOrder);
  668. dialogCreateOrderController.setRootController(this);
  669. }
  670.  
  671. this._oDialogCreateOrder.open();
  672. },
  673.  
  674. _isViewForm: function () {
  675. return (window.viewName === "message" || (window.viewName === "order" && window.orderPermission !== "read") || window.viewName ===
  676. "products" || window.viewName === "manualDelivery");
  677. },
  678.  
  679. navLegal: function (oEvent) {
  680. var model = this.getModel("footerModel");
  681. var obj = model.getProperty("/" + oEvent.getSource().getKey());
  682. var url = window.location.origin + this.formatter.getHrefDoc(obj);
  683. window.open(url, "_blank");
  684. },
  685.  
  686. navTodoDamm: function (oEvent) {
  687. var key = oEvent.getSource().getKey();
  688. var url = "";
  689.  
  690. switch (key) {
  691. case 'media':
  692. url = "https://hosteleria.damm.es";
  693. break;
  694. case 'corp':
  695. url = "http://www.dammcorporate.com/es";
  696. break;
  697. case 'link':
  698. url = "http://www.damm.es";
  699. break;
  700. default:
  701. break;
  702. }
  703. if (url !== "") {
  704. window.open(url, "_blank");
  705. }
  706. },
  707.  
  708. doLogout: function () {
  709. var urlLogOffService = "/destinations/logout"; //"https://sgdsgwdlh001:44300/sap/public/bc/icf/logoff"; //"http://<server>:<port>/sap/public/bc/icf/logoff";
  710. var urlGateway = "/destinations/logoutGW"; //"http://<server>:<port>/<serviceURL>";
  711.  
  712. $.ajax({
  713. type: "GET",
  714. url: urlLogOffService, //Clear SSO cookies: SAP Provided service to do that
  715. }).done(function (data) { //Now clear the authentication header stored in the browser
  716.  
  717. if (!document.execCommand("ClearAuthenticationCache")) { //"ClearAuthenticationCache" will work only for IE. Below code for other browsers
  718. $.ajax({
  719. type: "GET",
  720. url: urlGateway, //any URL to a Gateway service
  721. username: 'dummy', //dummy credentials: when request fails, will clear the authentication header
  722. password: 'dummy',
  723. statusCode: {
  724. 401: function () {
  725. //This empty handler function will prevent authentication pop-up in chrome/firefox
  726. sap.m.URLHelper.redirect("/logout.html", false);
  727. }
  728. },
  729. error: function () {
  730. //alert('reached error of wrong username password')
  731. }
  732. })
  733. }
  734. });
  735.  
  736. /* $.ajax({
  737. "type" : 'GET',
  738. "url": "/services/userapi/logout",
  739. "success": function() { window.location.replace("/logout.html"); }
  740. });*/
  741.  
  742. }
  743. });
  744. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement