Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sap.ui.define([
- "sap/ui/model/json/JSONModel",
- "sap/ui/Device",
- "gvdpl/documentsV2/util/DataManager",
- "gvdpl/documentsV2/util/Utils"
- ], function (JSONModel, Device, DataManager, Utils) {
- "use strict";
- return {
- _oData: {
- oNodeSet: [],
- sUploadURL: "/sap/opu/odata/GVDPL/XSS_DOCUMENTS2_SRV/MediaSet",
- oHeaderModel: [],
- oView: {
- sType: "",
- sSelHash: "",
- sDevice: "",
- sOrientation: ""
- },
- oConfig: {
- isUploadEnabled: false,
- isFlagsEnabled: false,
- isToolbarVisible: false
- },
- oFile: {
- sType: "",
- sIdFile: "",
- blobURL: "",
- base64: ""
- },
- oSearchHelpConfig: {
- docTypeState: "None",
- docTypeStateText: "",
- docDateState: "None",
- docDateStateText: "",
- doctypeSelectedKey: "",
- dateValue: ""
- },
- oSearchHelp: [],
- sFileIdentifierForSlug: ""
- },
- getUploadUrl: function () {
- return this._oData.sUploadURL;
- },
- getFileType: function () {
- return this._oData.oFile.sType;
- },
- getFileId: function () {
- return this._oData.oFile.sIdFile;
- },
- getFileUrl: function () {
- return this._oData.oFile.blobURL;
- },
- getFileBase64: function () {
- return this._oData.oFile.base64;
- },
- getNode: function () {
- return this._oData.oNodeSet;
- },
- getViewType: function () {
- return this._oData.oView.sType;
- },
- getSelHash: function () {
- return this._oData.oView.sSelHash;
- },
- getUploadEnabled: function () {
- return this._oData.oConfig.isUploadEnabled;
- },
- getFlagsEnabled: function () {
- return this._oData.oConfig.isFlagsEnabled;
- },
- getDevice: function () {
- return this._oData.oView.sDevice;
- },
- getOrientation: function () {
- return this._oData.oView.sOrientation;
- },
- getHeaderDetalils: function () {
- return this._oData.DetailsSet;
- },
- getSearchHelpValues: function () {
- var obj = {
- doctypeSelectedKey: this._oData.oSearchHelpConfig.doctypeSelectedKey,
- dateValue: this._oData.oSearchHelpConfig.dateValue
- };
- return obj;
- },
- getFileIdentifierForSlug: function () {
- return this._oData.sFileIdentifierForSlug;
- },
- setFileIdentifierForSlug: function (sFileIdentifierForSlug) {
- this._oData.sFileIdentifierForSlug = sFileIdentifierForSlug;
- },
- setDetailsConfig: function (isToolbarVisible) {
- this._oData.oConfig.isToolbarVisible = isToolbarVisible;
- },
- setSearchHelpConfig: function (docTypeState, docTypeStateText, docDateState, docDateStateText) {
- this._oData.oSearchHelpConfig.docTypeState = docTypeState;
- this._oData.oSearchHelpConfig.docTypeStateText = docTypeStateText;
- this._oData.oSearchHelpConfig.docDateState = docDateState;
- this._oData.oSearchHelpConfig.docDateStateText = docDateStateText;
- },
- setSearchHelpValues: function (doctypeSelectedKey, dateValue) {
- this._oData.oSearchHelpConfig.doctypeSelectedKey = doctypeSelectedKey;
- this._oData.oSearchHelpConfig.dateValue = dateValue;
- },
- setFileType: function (sFileType) {
- this._oData.oFile.sType = sFileType;
- },
- setFileId: function (fileId) {
- this._oData.oFile.sIdFile = fileId.replace(/\s+/g, "%20");
- },
- setDevice: function () {
- var device;
- if (sap.ui.Device.system.phone) {
- device = "phone";
- } else if (sap.ui.Device.system.tablet) {
- device = "tablet";
- } else {
- device = "desktop";
- }
- this._oData.oView.sDevice = device;
- },
- setOrientation: function () {
- var orientation;
- if (sap.ui.Device.orientation.portrait) {
- orientation = "vertical";
- } else {
- orientation = "horizontal";
- }
- this._oData.oView.sOrientation = orientation;
- },
- setNode: function () {
- var that = this;
- var promise;
- var dfd = jQuery.Deferred();
- var filter = [];
- var operator = sap.ui.model.FilterOperator.EQ;
- var sPath = "/NodeSet";
- filter.push(DataManager.setFilter("Selhash", operator, this.getSelHash()));
- filter.push(DataManager.setFilter("viewType", operator, this.getViewType()));
- promise = DataManager.readEntitySet(sPath, filter);
- promise.done(function (data) {
- that._oData.oNodeSet = data;
- sap.ui.core.BusyIndicator.hide();
- dfd.resolve();
- }).fail(function () {
- sap.ui.core.BusyIndicator.hide();
- });
- return dfd.promise();
- },
- setSearchHelp: function () {
- var that = this;
- var promise;
- var dfd = jQuery.Deferred();
- var filter = [];
- var operator = sap.ui.model.FilterOperator.EQ;
- var sPath = "/SearchHelpSet";
- filter.push(DataManager.setFilter("Selhash", operator, this.getSelHash()));
- filter.push(DataManager.setFilter("Field", operator, "DOCTYPE"));
- //filter.push(DataManager.setFilter("viewType", operator, this.getViewType()));
- promise = DataManager.readEntitySetSearchHelp(sPath, filter);
- promise.done(function (data) {
- that._oData.oSearchHelp = data;
- sap.ui.core.BusyIndicator.hide();
- dfd.resolve();
- }).fail(function () {
- sap.ui.core.BusyIndicator.hide();
- });
- return dfd.promise();
- },
- setUploadEnabled: function () {
- var that = this;
- var promise;
- var dfd = jQuery.Deferred();
- //var key = "('" + this.getSelHash() + "')";
- var key = "(Selhash='" + this.getSelHash() + "',viewType='" + this.getViewType() + "')";
- var sPath = "/ConfigSet";
- promise = DataManager.readEntity(sPath, key);
- promise.done(function (data) {
- that._oData.oConfig.isUploadEnabled = data.UploadEnabled;
- that._oData.oConfig.isFlagsEnabled = data.FlagsEnabled;
- sap.ui.core.BusyIndicator.hide();
- dfd.resolve();
- }).fail(function () {
- sap.ui.core.BusyIndicator.hide();
- });
- return dfd.promise();
- },
- setHeaderDetails: function (fileId) {
- var that = this;
- var promise;
- var dfd = jQuery.Deferred();
- var key = "(Selhash='" + this.getSelHash() + "',viewType='" + this.getViewType() + "',id='" + fileId + "')";
- var sPath = "/DetailSet";
- promise = DataManager.readEntity(sPath, key);
- promise.done(function (data) {
- var obj = Utils.buildHeaderElements(data.content);
- that._oData.oHeaderModel = obj;
- sap.ui.core.BusyIndicator.hide();
- dfd.resolve();
- }).fail(function () {
- sap.ui.core.BusyIndicator.hide();
- });
- return dfd.promise();
- },
- //preview file
- setBinaryDocument: function (fileId) {
- var that = this;
- var promise;
- var dfd = jQuery.Deferred();
- var contentType = Utils.setMimeType(this.getFileType());
- var key = "(Selhash='" + this.getSelHash() + "',viewType='" + this.getViewType() + "',id='" + fileId + "')";
- var sPath = "/FileSet";
- promise = DataManager.readEntity(sPath, key);
- promise.done(function (data) {
- that._oData.oFile.base64 = data.bin;
- that._oData.oFile.blobURL = URL.createObjectURL(Utils._blobUrlFromBase64(data.bin, contentType));
- sap.ui.core.BusyIndicator.hide();
- dfd.resolve();
- }).fail(function () {
- sap.ui.core.BusyIndicator.hide();
- });
- return dfd.promise();
- },
- downloadDocument: function (fileId) {
- var key = "(Selhash='" + this.getSelHash() + "',viewType='" + this.getViewType() + "',id='" + fileId + "')/$value";
- var sPath = "/MediaSet";
- var URL = DataManager.service() + sPath + key;
- window.open(URL);
- },
- setEmptyHeader: function () {
- this._oData.oHeaderModel = [];
- },
- setViewType: function (sViewType) {
- this._oData.oView.sType = sViewType;
- },
- setSelHash: function (sSelHash) {
- if (sSelHash) {
- this._oData.oView.sSelHash = sSelHash;
- } else {
- this._oData.oView.sSelHash = "";
- }
- },
- createDeviceModel: function () {
- var oModel = new JSONModel(Device);
- oModel.setDefaultBindingMode("OneWay");
- return oModel;
- }
- };
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement