123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439 |
- /*******************************************************************************
- * IBM Confidential
- *
- * OCO Source Materials
- *
- * A and PM: PD
- *
- * (c) Copyright IBM Corp. 2014, 2015
- *
- * The source code for this program is not published or otherwise divested of
- * its trade secrets, irrespective of what has been deposited with the U.S.
- * Copyright Office.
- ******************************************************************************/
- define([
- "dojo/_base/declare",
- "dijit/_WidgetBase",
- "dijit/_TemplatedMixin",
- "dijit/_WidgetsInTemplateMixin",
- "dojo/text!pd/ui/templates/_base.html",
- "dojo/dom",
- "pd/widgets/ColumnGrid",
- "pd/widgets/PreviewGrid",
- "pd/data/PdSpecStore",
- "dojo/data/ObjectStore",
- "dojo/string",
- "pd/widgets/ComboBox",
- "pd/data/PdDataStore",
- "pd/widgets/SaveDialog",
- "pd/widgets/MessageDialog",
- "dojo/dom-construct",
- "bux/application/controllers/ForestModelsSubController",
- "bux/data/RestStore",
- "bux/data/AtomHelper",
- "pd/widgets/Uploader",
- "pd/widgets/ProgressBar",
- "dojo/domReady!"
- ], function(declare, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin,
- template, dom, ColumnGrid, PreviewGrid, PdSpecStore, ObjectStore,
- string, ComboBox, PdDataStore, SaveDialog, MessageDialog, domConstruct, ForestModelsSubController) {
-
- var self = this;
-
- new ForestModelsSubController();
-
- return declare("pd/ui/_base", [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
-
-
- //default to "normal", can be "edit", "refresh"
- mode: pd.statics.MODE_NORMAL,
-
- //left side meta data grid
- columnGrid: null,
-
- //data preview grid
- previewGrid: null,
-
- //column name comboBox
- comboBox: null,
-
- //data set name
- dataSetName: "",
-
- //save as package name
- saveAsPackageName: "",
-
- templateString : template,
-
- getDataSetName: function() {
- //to be overridden
- },
- getDataSetStoreID: function() {
- //to be overridden
- },
-
- renderMainContent: function(pdSpecValue) {
- //to be overridden
- },
-
- _getFileFullName: function() {
- return pd_uploader.get("value")[0].name;
- },
-
- _getFileName: function() {
- var fileName = this._getFileFullName();
- var lastPeriod = fileName.lastIndexOf(".");
- if (lastPeriod > 0) {
- fileName = fileName.substring(0, lastPeriod);
- }
- return fileName;
- },
-
- _getFileType: function() {
- // Summary:
- // According to the current External Data implementation, the supported file types are CSV,
- // Excel2003 and XML, and the file type is determined by the file extension. For xls
- // and xlsx, it's always Excel2003
-
- var type = "";
- var extension = pd_uploader.getFileType(this._getFileFullName())
-
- switch (extension) {
- case "XLS":
- case "XLSX":
- type = "Excel2003";
- break;
- case "CSV":
- type = "CSV";
- break;
- default:
- // for now, rely on server side to throw an exception.
- }
- return type;
- },
-
- setStatus: function(status) {
- switch(status){
- case pd.statics.STATUS_INIT:
- self.isProcessing = false;
- pd_progressBar.init(pd_uploader.uploadType);
- pd_uploader.uploadUrl = this.getTargetUrl();
- break;
- case pd.statics.STATUS_UPLOAD:
- self.isProcessing = false;
- pd_progressBar.onStageZero();
- pd_uploader.set("disabled", true);
- break;
- case pd.statics.STATUS_PROCESS:
- self.isProcessing = true;
- pd_progressBar.onStageTwo(PDMSG.IPT.IDS_IPT_PROGRESS_STAGE_LOAD);
- pd_uploader.set("disabled", true);
- break;
- case pd.statics.STATUS_FINISH:
- self.isProcessing = false;
- pd_progressBar.onStageThree();
- pd_uploader.set("disabled", false);
- break;
- default:
- }
- },
-
- _uploaderOnchangeHandler: function() {
- this.dataSetName = this.getDataSetName();
- this.pd_uploaderForm.inSpec.value = '<input><dataSet type="'
- + this._getFileType()
- + '"><name>' + this._getFileName() + '</name>'
- + '<sourcePath>'
- + this._getFileFullName()
- + '</sourcePath>'
- + '</dataSet>'
- + '</input>';
- this.setStatus(pd.statics.STATUS_UPLOAD);
- },
-
- _uploaderOnerrorHandler: function(err) {
- pd_uploader.reset();
- this.setStatus(pd.statics.STATUS_FINISH);
-
- var pdError = {};
- if (typeof err == "string"){
- pdError.message = err;
- } else {
- pdError = err;
- }
-
- //try to analysis unexpected response and improve the error messages.
- var response = pdError.response;
- if (response) {
- if (dojo.isSafari) {
- //safari response is plain text.
- pdError.detail = response;
- } else if (dojo.isIE){
- var doc = response.documentElement;
- if (doc && doc.document) {
- if (!pdError.message){
- pdError.message = doc.document.title;
- }
- pdError.detail = doc.innerHTML;
- }
- } else {
- if (!pdError.message){
- pdError.message = response.title;
- }
- if (response.parseError){
- pdError.detail = null;
- } else {
- pdError.detail = response.body?response.body.innerHTML : response.xml;
- }
- }
- }
-
- if (pdError.name == pd.CAM_PASSPORT_ERROR){
- pd.showLogonDialog();
- return;
- } else {
- //RTC 12700: The error message displayed when the importing phase of large files times out could be improved
- if (pdError.name == "504" || pdError.message.indexOf("504") > -1) {
- pd.messageBox(pd.statics.MB_WARNING, pdError.message,
- PDMSG.ERR.IDS_ERR_BACKGROUND_RUNNING_MESSAGE, pdError.detail);
- return;
- }
-
- //RTC 15489, handle IE permission denied in case of IIS and PassThrough case.
- if (pdError.message.indexOf("Permission denied") > -1) {
- pd.messageBox(pd.statics.MB_ERROR, pdError.message,
- PDMSG.ERR.IDS_ERR_EXCEED_REQUEST_CONTENT_LENGTH, null);
- return;
- }
-
- //in IIS case
- if (pdError.name == "404" || pdError.message.indexOf("404") > -1) {
- pd.messageBox(pd.statics.MB_ERROR, pdError.message,
- PDMSG.ERR.IDS_ERR_EXCEED_REQUEST_CONTENT_LENGTH, pdError.detail);
- return;
- }
-
- //in IHS, Apache cases
- if (pdError.name == "413" || pdError.message.indexOf("413") > -1) {
- pd.messageBox(pd.statics.MB_ERROR, pdError.message,
- PDMSG.ERR.IDS_ERR_EXCEED_REQUEST_CONTENT_LENGTH, null);
- return;
- }
-
- //Display generic error if none of above
- pd.messageBox(pd.statics.MB_ERROR, PDMSG.ERR.IDS_ERR_FILE_UPLOAD, pdError.message, pdError.detail);
- return;
- }
- },
-
- _uploaderOnprogressHandler: function(evt) {
- if (evt.type == "progress"){
- if (this.mode == pd.statics.MODE_EDIT){
- self.isProcessing = true;
- pd_progressBar.onStageTwo(PDMSG.IPT.IDS_IPT_PROGRESS_STAGE_LOAD);
- } else {
- var percent = Math.round(evt.decimal * 100);
- var currentLoad = evt.bytesLoaded - pd_progressBar.previousBytesLoaded;
- if (currentLoad > pd_progressBar.maxBytesPerLoad){
- pd_progressBar.maxBytesPerLoad = currentLoad;
- }
-
- if ((evt.bytesTotal - evt.bytesLoaded) < pd_progressBar.maxBytesPerLoad) {
- self.isProcessing = true;
- pd_progressBar.onStageOne(100);
- pd_progressBar.onStageTwo();
- } else {
- pd_progressBar.onStageOne(percent);
- }
- pd_progressBar.previousBytesLoaded = evt.bytesLoaded;
- }
- } else {
- self.isProcessing = false;
- }
- },
-
- _uploaderOncompleteHandler: function(response, isGovernorCheck) {
- try {
- if (!isGovernorCheck) {
- this.setStatus(pd.statics.STATUS_FINISH);
- }
- pd.parseResponse(response);
-
- var pdSpecDoc = null;
- if (dojo.isSafari) {
- var responseNode = domConstruct.toDom(response);
- if (responseNode.querySelector) {
- pdSpecDoc = responseNode.querySelector("#pdSpec");
- }
- } else {
- pdSpecDoc = response.getElementById("pdSpec");
- }
- if (pdSpecDoc) {
- if (!isGovernorCheck) {
- var pdSpecValue = pdSpecDoc.textContent || pdSpecDoc.innerText;
- this.renderMainContent(pdSpecValue);
- }
- } else {
- //something wrong, let error handler take care of it
- throw({
- response: response
- });
- }
- return true;
- } catch (err) {
- this._uploaderOnerrorHandler(err);
- return false;
- }
- },
-
- _renderMainContent: function(pdSpecValue) {
- this.destroy();
-
- //create preview grid
- var pdDataStore = new PdDataStore({xmlInput: pdSpecValue});
- var dataStore = ObjectStore({objectStore: pdDataStore});
-
- pd.placeDiv("pd_preview_grid_div", pd_previewContainer.domNode);
- this.previewGrid = new PreviewGrid({
- store: dataStore,
- "aria-label":PDMSG.ACC.IDS_ACC_GROUP_LABEL_PREVIEW_PANE
- },"pd_preview_grid_div");
- this.previewGrid.startup();
-
- //create column view grid
- var pdSpecStore = new PdSpecStore({xmlInput: pdSpecValue});
- var specStore = ObjectStore({objectStore: pdSpecStore});
- pd.placeDiv("pd_column_grid_div", pd_columnGridContainer.domNode);
- this.columnGrid = new ColumnGrid({
- store: specStore,
- previewGrid: this.previewGrid,
- "aria-label":PDMSG.ACC.IDS_ACC_GROUP_LABEL_METADATA_TABLE
- },"pd_column_grid_div");
- this.columnGrid.startup();
-
- //create comboBox
- pd.placeDiv("pd_column_combobox_div", pd_columnComboboxContainer.domNode);
- this.comboBox = new ComboBox({
- store: pdSpecStore,
- searchAttr: "name",
- columnGrid: this.columnGrid,
- "aria-label":PDMSG.ACC.IDS_ACC_GROUP_LABEL_COLUMN_NAME_SEARCH_BOX
- },"pd_column_combobox_div");
- this.comboBox.startup();
- },
-
- _publishBtnOnclickHandler: function(){
- if (this.columnGrid.selection.getSelected().length == 0){
- pd.messageBox(pd.statics.MB_ERROR, PDMSG.ERR.IDS_ERR_NO_COLUMN_INCLUDED);
- return false;
- }
- if (!this.columnGrid.hasFactSelected()) {
- var dlg = new MessageDialog.Confirm(PDMSG.IPT.IDS_IPT_APPLICATION_TITLE,
- PDMSG.IPT.IDS_IPT_NO_FACT_CONFIRM_MESSAGE,
- PDMSG.IPT.IDS_IPT_NO_FACT_CONFIRM_DETAILS,
- dojo.hitch(this, this._showPackageExplorer));
- dlg.startup();
- dlg.show();
- } else {
- this._showPackageExplorer();
- }
- },
-
- _closeBtnOnclickHandler: function() {
-
- pd_uploader.set("disabled", true);
- if (this.mode == pd.statics.MODE_NORMAL && self.isProcessing) {
- pd_progressBar.onCancel();
- this._removeEventListeners();
- pd_onClose(self.isProcessing,g_pd_backURL);
- } else {
- this._removeEventListeners();
- location.href = g_pd_backURL;
- }
- },
-
- _showPackageExplorer: function() {
- var oDlg = new SaveDialog({
- title: PDMSG.IPT.IDS_IPT_FILE_DIALOG_TITLE,
- filter: 'content-folder',
- sMainActionButtonLabel: PDMSG.IPT.IDS_IPT_PUBLISH_BUTTON,
- "class": "bux-fileDialog",
- saveAsHandler: dojo.hitch(this, this._saveAsHandler),
- sLocationLabel: BUXMSG.FDG.IDS_FDG_SAVE_AS_LOCATION,
- pdDefaultName: this.dataSetName
- });
- oDlg.startup();
- oDlg.show();
- },
-
- _saveAsHandler: function(saveAsName, oLink, _callBackFunction, oContainerItem){
- this.folderSearchPath = oContainerItem.i.cm$searchPath;
- D_ManagePersonalData.m_sTargetPath = this.folderSearchPath;
- D_ManagePersonalData.m_sTargetName = this.saveAsPackageName = saveAsName;
- D_ManagePersonalData.m_docInputXML = this.columnGrid.pdGetXml();
- D_ManagePersonalData.pd_packageOverwriteConfirm = dojo.hitch(this, this.packageOverwriteConfirm);
- D_ManagePersonalData.f_checkPackageNameOnOK();
- },
-
- packageOverwriteConfirm: function(){
- var dlg = new MessageDialog.Confirm(PDMSG.IPT.IDS_IPT_APPLICATION_TITLE,
- string.substitute(PDMSG.IPT.IDS_IPT_OVERWRITE_PACKAGE_CONFIRM_MESSAGE,
- {0: this.saveAsPackageName}), null,
- dojo.hitch(D_ManagePersonalData, D_ManagePersonalData.f_publishPackage));
- dlg.startup();
- dlg.show();
- return dlg;
- },
-
- postCreate : function() {
- this.pdsContentLabelNode.innerHTML = PDMSG.IPT.IDS_IPT_FILE_NAME_LABEL+" ";
- this.pd_uploaderForm = dom.byId("pd_uploaderForm");
- this.setStatus(pd.statics.STATUS_INIT);
-
- this._eventListeners[this._eventListeners.length] = this.connect(pd_uploader, "onChange", this._uploaderOnchangeHandler);
- this._eventListeners[this._eventListeners.length] = this.connect(pd_uploader, "onProgress", dojo.hitch(this, this._uploaderOnprogressHandler));
- this._eventListeners[this._eventListeners.length] = this.connect(pd_uploader, "onComplete", this._uploaderOncompleteHandler);
- this._eventListeners[this._eventListeners.length] = this.connect(pd_uploader, "onError", this._uploaderOnerrorHandler);
- },
-
- startup: function() {
- this.inherited(arguments);
- this._eventListeners[this._eventListeners.length] = this.connect(pd_publishBtn, "onClick", this._publishBtnOnclickHandler);
- this._eventListeners[this._eventListeners.length] = this.connect(pd_cancelBtn, "onClick", dojo.hitch(this, this._closeBtnOnclickHandler));
- this._eventListeners[this._eventListeners.length] = this.connect(pd_closeBtn, "onclick", dojo.hitch(this, this._closeBtnOnclickHandler));
-
- pd.connect.subscribe("/pd/widgets/grid/cells/applyChange", dojo.hitch(this, function(){
- this.columnGrid.edit.apply();
- }));
-
- pd.setSupplementId(pd_publishBtn.domNode, "IMPORT_DIALOG_PUBLISH_BUTTON");
- pd.setSupplementId(pd_cancelBtn.domNode, "IMPORT_DIALOG_CANCEL_BUTTON");
- },
-
- destroy: function() {
- if (this.columnGrid){
- this.columnGrid.destroy();
- }
- if (this.comboBox){
- this.comboBox.destroy();
- }
- if (this.previewGrid){
- this.previewGrid.destroy();
- }
- },
-
- _removeEventListeners: function() {
- for (var i=0; i < this._eventListeners.length; i++) {
- dojo.disconnect(this._eventListeners[i]);
- }
- },
- isProcessing: false,
- _eventListeners: []
- });
- }
- );
|