Advertisement
Guest User

Untitled

a guest
Feb 18th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.75 KB | None | 0 0
  1. sap.ui.define([
  2. "sap/ui/model/json/JSONModel",
  3. "sap/ui/Device",
  4. "gvdpl/documentsV2/util/DataManager",
  5. "gvdpl/documentsV2/util/Utils"
  6. ], function (JSONModel, Device, DataManager, Utils) {
  7. "use strict";
  8.  
  9. return {
  10.  
  11. _oData: {
  12. oNodeSet: [],
  13. sUploadURL: "/sap/opu/odata/GVDPL/XSS_DOCUMENTS2_SRV/MediaSet",
  14. oHeaderModel: [],
  15. oView: {
  16. sType: "",
  17. sSelHash: "",
  18. sDevice: "",
  19. sOrientation: ""
  20. },
  21. oConfig: {
  22. isUploadEnabled: false,
  23. isFlagsEnabled: false,
  24. isToolbarVisible: false
  25. },
  26. oFile: {
  27. sType: "",
  28. sIdFile: "",
  29. blobURL: "",
  30. base64: ""
  31. },
  32. oSearchHelpConfig: {
  33. docTypeState: "None",
  34. docTypeStateText: "",
  35. docDateState: "None",
  36. docDateStateText: "",
  37. doctypeSelectedKey: "",
  38. dateValue: ""
  39. },
  40. oSearchHelp: [],
  41. sFileIdentifierForSlug: ""
  42. },
  43.  
  44. getUploadUrl: function () {
  45. return this._oData.sUploadURL;
  46. },
  47.  
  48. getFileType: function () {
  49. return this._oData.oFile.sType;
  50. },
  51.  
  52. getFileId: function () {
  53. return this._oData.oFile.sIdFile;
  54. },
  55.  
  56. getFileUrl: function () {
  57. return this._oData.oFile.blobURL;
  58. },
  59.  
  60. getFileBase64: function () {
  61. return this._oData.oFile.base64;
  62. },
  63.  
  64. getNode: function () {
  65. return this._oData.oNodeSet;
  66. },
  67.  
  68. getViewType: function () {
  69. return this._oData.oView.sType;
  70. },
  71.  
  72. getSelHash: function () {
  73. return this._oData.oView.sSelHash;
  74. },
  75.  
  76. getUploadEnabled: function () {
  77. return this._oData.oConfig.isUploadEnabled;
  78. },
  79.  
  80. getFlagsEnabled: function () {
  81. return this._oData.oConfig.isFlagsEnabled;
  82. },
  83.  
  84. getDevice: function () {
  85. return this._oData.oView.sDevice;
  86. },
  87.  
  88. getOrientation: function () {
  89. return this._oData.oView.sOrientation;
  90. },
  91.  
  92. getHeaderDetalils: function () {
  93. return this._oData.DetailsSet;
  94. },
  95.  
  96. getSearchHelpValues: function () {
  97. var obj = {
  98. doctypeSelectedKey: this._oData.oSearchHelpConfig.doctypeSelectedKey,
  99. dateValue: this._oData.oSearchHelpConfig.dateValue
  100. };
  101. return obj;
  102. },
  103.  
  104. getFileIdentifierForSlug: function () {
  105. return this._oData.sFileIdentifierForSlug;
  106. },
  107.  
  108. setFileIdentifierForSlug: function (sFileIdentifierForSlug) {
  109. this._oData.sFileIdentifierForSlug = sFileIdentifierForSlug;
  110. },
  111.  
  112. setDetailsConfig: function (isToolbarVisible) {
  113. this._oData.oConfig.isToolbarVisible = isToolbarVisible;
  114. },
  115.  
  116. setSearchHelpConfig: function (docTypeState, docTypeStateText, docDateState, docDateStateText) {
  117. this._oData.oSearchHelpConfig.docTypeState = docTypeState;
  118. this._oData.oSearchHelpConfig.docTypeStateText = docTypeStateText;
  119. this._oData.oSearchHelpConfig.docDateState = docDateState;
  120. this._oData.oSearchHelpConfig.docDateStateText = docDateStateText;
  121. },
  122.  
  123. setSearchHelpValues: function (doctypeSelectedKey, dateValue) {
  124. this._oData.oSearchHelpConfig.doctypeSelectedKey = doctypeSelectedKey;
  125. this._oData.oSearchHelpConfig.dateValue = dateValue;
  126. },
  127.  
  128. setFileType: function (sFileType) {
  129. this._oData.oFile.sType = sFileType;
  130. },
  131.  
  132. setFileId: function (fileId) {
  133. this._oData.oFile.sIdFile = fileId.replace(/\s+/g, "%20");
  134. },
  135.  
  136. setDevice: function () {
  137. var device;
  138. if (sap.ui.Device.system.phone) {
  139. device = "phone";
  140. } else if (sap.ui.Device.system.tablet) {
  141. device = "tablet";
  142. } else {
  143. device = "desktop";
  144. }
  145. this._oData.oView.sDevice = device;
  146. },
  147.  
  148. setOrientation: function () {
  149. var orientation;
  150. if (sap.ui.Device.orientation.portrait) {
  151. orientation = "vertical";
  152. } else {
  153. orientation = "horizontal";
  154. }
  155. this._oData.oView.sOrientation = orientation;
  156. },
  157.  
  158. setNode: function () {
  159. var that = this;
  160. var promise;
  161. var dfd = jQuery.Deferred();
  162. var filter = [];
  163. var operator = sap.ui.model.FilterOperator.EQ;
  164. var sPath = "/NodeSet";
  165.  
  166. filter.push(DataManager.setFilter("Selhash", operator, this.getSelHash()));
  167. filter.push(DataManager.setFilter("viewType", operator, this.getViewType()));
  168.  
  169. promise = DataManager.readEntitySet(sPath, filter);
  170. promise.done(function (data) {
  171.  
  172. that._oData.oNodeSet = data;
  173. sap.ui.core.BusyIndicator.hide();
  174. dfd.resolve();
  175.  
  176. }).fail(function () {
  177. sap.ui.core.BusyIndicator.hide();
  178. });
  179.  
  180. return dfd.promise();
  181.  
  182. },
  183.  
  184. setSearchHelp: function () {
  185. var that = this;
  186. var promise;
  187. var dfd = jQuery.Deferred();
  188. var filter = [];
  189. var operator = sap.ui.model.FilterOperator.EQ;
  190. var sPath = "/SearchHelpSet";
  191.  
  192. filter.push(DataManager.setFilter("Selhash", operator, this.getSelHash()));
  193. filter.push(DataManager.setFilter("Field", operator, "DOCTYPE"));
  194. //filter.push(DataManager.setFilter("viewType", operator, this.getViewType()));
  195.  
  196. promise = DataManager.readEntitySetSearchHelp(sPath, filter);
  197. promise.done(function (data) {
  198.  
  199. that._oData.oSearchHelp = data;
  200. sap.ui.core.BusyIndicator.hide();
  201. dfd.resolve();
  202.  
  203. }).fail(function () {
  204. sap.ui.core.BusyIndicator.hide();
  205. });
  206.  
  207. return dfd.promise();
  208.  
  209. },
  210.  
  211. setUploadEnabled: function () {
  212. var that = this;
  213. var promise;
  214. var dfd = jQuery.Deferred();
  215. //var key = "('" + this.getSelHash() + "')";
  216. var key = "(Selhash='" + this.getSelHash() + "',viewType='" + this.getViewType() + "')";
  217. var sPath = "/ConfigSet";
  218.  
  219. promise = DataManager.readEntity(sPath, key);
  220. promise.done(function (data) {
  221.  
  222. that._oData.oConfig.isUploadEnabled = data.UploadEnabled;
  223. that._oData.oConfig.isFlagsEnabled = data.FlagsEnabled;
  224. sap.ui.core.BusyIndicator.hide();
  225. dfd.resolve();
  226.  
  227. }).fail(function () {
  228. sap.ui.core.BusyIndicator.hide();
  229. });
  230.  
  231. return dfd.promise();
  232. },
  233.  
  234. setHeaderDetails: function (fileId) {
  235. var that = this;
  236. var promise;
  237. var dfd = jQuery.Deferred();
  238. var key = "(Selhash='" + this.getSelHash() + "',viewType='" + this.getViewType() + "',id='" + fileId + "')";
  239. var sPath = "/DetailSet";
  240.  
  241. promise = DataManager.readEntity(sPath, key);
  242. promise.done(function (data) {
  243.  
  244. var obj = Utils.buildHeaderElements(data.content);
  245. that._oData.oHeaderModel = obj;
  246. sap.ui.core.BusyIndicator.hide();
  247. dfd.resolve();
  248.  
  249. }).fail(function () {
  250. sap.ui.core.BusyIndicator.hide();
  251. });
  252.  
  253. return dfd.promise();
  254. },
  255.  
  256. //preview file
  257. setBinaryDocument: function (fileId) {
  258. var that = this;
  259. var promise;
  260. var dfd = jQuery.Deferred();
  261. var contentType = Utils.setMimeType(this.getFileType());
  262. var key = "(Selhash='" + this.getSelHash() + "',viewType='" + this.getViewType() + "',id='" + fileId + "')";
  263. var sPath = "/FileSet";
  264.  
  265. promise = DataManager.readEntity(sPath, key);
  266. promise.done(function (data) {
  267.  
  268. that._oData.oFile.base64 = data.bin;
  269. that._oData.oFile.blobURL = URL.createObjectURL(Utils._blobUrlFromBase64(data.bin, contentType));
  270. sap.ui.core.BusyIndicator.hide();
  271. dfd.resolve();
  272.  
  273. }).fail(function () {
  274. sap.ui.core.BusyIndicator.hide();
  275. });
  276.  
  277. return dfd.promise();
  278. },
  279.  
  280. downloadDocument: function (fileId) {
  281. var key = "(Selhash='" + this.getSelHash() + "',viewType='" + this.getViewType() + "',id='" + fileId + "')/$value";
  282. var sPath = "/MediaSet";
  283. var URL = DataManager.service() + sPath + key;
  284. window.open(URL);
  285. },
  286.  
  287. setEmptyHeader: function () {
  288. this._oData.oHeaderModel = [];
  289. },
  290.  
  291. setViewType: function (sViewType) {
  292. this._oData.oView.sType = sViewType;
  293. },
  294.  
  295. setSelHash: function (sSelHash) {
  296. if (sSelHash) {
  297. this._oData.oView.sSelHash = sSelHash;
  298. } else {
  299. this._oData.oView.sSelHash = "";
  300. }
  301.  
  302. },
  303.  
  304. createDeviceModel: function () {
  305. var oModel = new JSONModel(Device);
  306. oModel.setDefaultBindingMode("OneWay");
  307. return oModel;
  308. }
  309.  
  310. };
  311. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement