SaveDialog.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*******************************************************************************
  2. * IBM Confidential
  3. *
  4. * OCO Source Materials
  5. *
  6. * A and PM: PD
  7. *
  8. * (c) Copyright IBM Corp. 2014
  9. *
  10. * The source code for this program is not published or otherwise divested of
  11. * its trade secrets, irrespective of what has been deposited with the U.S.
  12. * Copyright Office.
  13. ******************************************************************************/
  14. define([
  15. "dojo/_base/declare",
  16. "bux/dialogs/FileDialog",
  17. "dojo/_base/array"
  18. ],function(declare, FileDialog, array){
  19. var pdFileDialog = declare("pd/widgets/FileDialog", [FileDialog], {
  20. //override bux function, so that my folder will be the default.
  21. createSpecialLocationsUiElements: function(topLevelNodes) {
  22. if ( !topLevelNodes ) {
  23. // this.model.getChildren() is calling the callback with null when there's an error in the request.
  24. this.onCancel();
  25. return;
  26. }
  27. this._topLevelNodes = topLevelNodes;
  28. //Reverse order for now so that the Public Folders appears first.
  29. for (var i = topLevelNodes.length - 1; i >= 0; i--) {
  30. this._addSpecialLocationFromTreeView(topLevelNodes[i]);
  31. }
  32. this.onSpecialLocationsClick("myFolders");
  33. this._locationSelector.dropDown = this._locationSelector.createMenu();
  34. this._locationSelector.startup();
  35. },
  36. _addSpecialLocationFromTreeView: function(node) {
  37. //add supplementId for location buttons.
  38. this.inherited(arguments);
  39. var sNodeClass = node.i.bux$uiclass;
  40. var parentNode = this._leftSectionSpecialLocations.domNode.childNodes;
  41. var currentNode = parentNode[parentNode.length - 1];
  42. if (sNodeClass == "publicFolders") {
  43. pd.setSupplementId(currentNode, "PUBLISH_DIALOG_PUBLIC_FOLDERS");
  44. } else if (sNodeClass == "myFolders") {
  45. pd.setSupplementId(currentNode, "PUBLISH_DIALOG_MY_FOLDERS");
  46. }
  47. },
  48. onNewFolderButtonClick: function() {
  49. //add supplementId for input box and action buttons in newFolder dialog.
  50. this.inherited(arguments);
  51. if (this.simplePromptDialog) {
  52. var textField = this.simplePromptDialog.textField;
  53. pd.setSupplementId(textField.domNode,
  54. "PUBLISH_DIALOG_NEW_FOLDER_NAME_INPUT");
  55. pd.setSupplementId(textField.oDlgBtns[0].domNode,
  56. "PUBLISH_DIALOG_NEW_FOLDER_OK_BUTTON");
  57. pd.setSupplementId(textField.oDlgBtns[1].domNode,
  58. "PUBLISH_DIALOG_NEW_FOLDER_CANCEL_BUTTON");
  59. }
  60. },
  61. _newFolderErrHandler: function(folderName, error){
  62. var sMessageDesc = BUXMSG.FDG.IDS_FDG_NEW_FOLDER_ERROR_DESC;
  63. var bFolderExists = (error.message && (error.message.indexOf('CM-REQ-4024')>=0 || error.message.indexOf('BUX-ACM-1507')>=0)) || error.status==409;
  64. if(bFolderExists){
  65. sMessageDesc = dojo.string.substitute(BUXMSG.FDG.IDS_FDG_NEW_FOLDER_ALREADY_EXISTS_ERROR, [bux.Bidi.enforceTextDir(folderName)]);
  66. }else{
  67. this.simplePromptDialog.destroyRecursive();
  68. delete this.simplePromptDialog;
  69. }
  70. return pd.messageBox(pd.statics.MB_ERROR, BUXMSG.FDG.IDS_FDG_NEW_FOLDER_ERROR,
  71. sMessageDesc, error.message);
  72. }
  73. });
  74. var SaveDialog = declare("pd/widgets/SaveDialog", [bux.dialogs.SaveDialog, pdFileDialog], {
  75. constructor: function(args){
  76. this.inherited(arguments);
  77. this.pdDefaultName = args.pdDefaultName;
  78. var ALLOWED_OPERATION = ["refresh", "createNewFolder"];
  79. dojo.mixin(bux.IWidgetUtils, {
  80. //override bux object so that "refresh" and "createNewFolder" button showed in the publish dialog.
  81. getIWidgetById: function(){
  82. return {
  83. iScope:{
  84. isOperationAllowed: function(operation) {
  85. return array.indexOf(ALLOWED_OPERATION, operation) != -1;
  86. }
  87. }
  88. };
  89. }
  90. });
  91. },
  92. checkAndEnableMainAction: function(_item) {
  93. var sSaveAsName = this._objectNameField.get('value');
  94. if(bux.Bidi.getTextDir()) {
  95. if(!_item && dojo.isIE) {
  96. this._objectNameField.focusNode.style.overflowX = "visible";
  97. }
  98. if(!_item || !_item.keyCode || bux.Bidi.doesKeyImpactsDir(_item.keyCode)) {
  99. bux.Bidi.setInputDirByValue(this._objectNameField.domNode, sSaveAsName);
  100. }
  101. }
  102. var bIsValid = (
  103. ((this.oCurrentPath && (this.oCurrentPath.bux$uiclass == "myFolders" ||
  104. this.oCurrentPath.bux$uiclass == "publicFolders")) ||
  105. (_item && bux.CMHelper.hasPermissions(_item.cm$permissions, "WT&") &&
  106. this._getCurrentNodeFromView())) &&
  107. (sSaveAsName && dojo.trim(sSaveAsName).length >0 ? true : false));
  108. if(this._aButtonObjects && this._aButtonObjects[0]){
  109. this._aButtonObjects[0].set( 'disabled', !bIsValid );
  110. }
  111. this._bCanExecuteAction = bIsValid;
  112. return bIsValid;
  113. },
  114. onMainAction: function() {
  115. if (this.saveAsHandler) {
  116. var saveAsName = this._objectNameField.get('value');
  117. // check for presence of both ' and " - this is not supported by CM
  118. if (-1 != saveAsName.indexOf("'") && -1 != saveAsName.indexOf('"')) {
  119. bux.messageBox(bux.MB_ERROR,
  120. BUXMSG.CDG.IDS_CDG_SAVE_CHANGE_NAME_TITLE,
  121. dojo.string.substitute(BUXMSG.EDG.IDS_EDG_ERROR_MIXED_USE_QUOTES, [bux.Bidi.enforceTextDir(saveAsName)]));
  122. return;
  123. }
  124. var containerNodeFromView = this._getCurrentNodeFromView();
  125. var containerNode = null;
  126. if (containerNodeFromView) {
  127. var containerNodeItem = containerNodeFromView.getItem();
  128. if (containerNodeItem && containerNodeItem.cm$objectClass != "folder" && containerNodeItem.cm$objectClass != "package") {
  129. containerNode = containerNodeFromView.getParent();
  130. } else {
  131. containerNode = containerNodeFromView;
  132. }
  133. }
  134. var fHandler = this.saveAsHandler;
  135. var oLink = null;
  136. var fCallback = this.callBackFunction;
  137. if (saveAsName && containerNode &&
  138. this.getCurrentTreeView().getNodeLink(containerNode, "up")) {
  139. oLink = this.getCurrentTreeView().getNodeLink(containerNode, "self");
  140. } else if ((this.oCurrentPath.bux$uiclass == "myFolders" ||
  141. this.oCurrentPath.bux$uiclass == "publicFolders") && saveAsName) {
  142. var _myFolderPath = dojox.json.query("?rel='self'",this.oCurrentPath.link);
  143. oLink = _myFolderPath[0].href;
  144. }
  145. var oContainerItem = {"i" : this._getCurrentSelectedContainer()};//Extra parent container item
  146. if (oLink) {
  147. // Refresh the Tree's data for the next time the dialog is opened.
  148. if (this.treeView) {
  149. this.treeView.clearTree();
  150. }
  151. if (this.listView) {
  152. this.listView.clearTree();
  153. }
  154. this.hide();
  155. setTimeout(function() {fHandler(saveAsName, oLink, fCallback, oContainerItem)}, 10);
  156. } else {
  157. window.alert(BUXMSG.FDG.IDS_FDG_INVALID_ARGUMENTS);
  158. }
  159. }
  160. },
  161. startup: function() {
  162. this.inherited(arguments);
  163. this._objectNameField.set("value", this.pdDefaultName);
  164. //add supplementId for publish dialog
  165. pd.setSupplementId(this.domNode, "PUBLISH_DIALOG");
  166. //add supplementId for action buttons
  167. pd.setSupplementId(this._aButtonObjects[0].domNode,
  168. "PUBLISH_DIALOG_PUBLISH_BUTTON");
  169. pd.setSupplementId(this._aButtonObjects[1].domNode,
  170. "PUBLISH_DIALOG_CANCEL_BUTTON");
  171. //add supplementId for newFolder button
  172. pd.setSupplementId(this.newFolderButton.domNode,
  173. "PUBLISH_DIALOG_NEW_FOLDER");
  174. //add supplementId for name input box
  175. pd.setSupplementId(this._objectNameField.domNode,
  176. "PUBLISH_DIALOG_NAME_INPUT");
  177. }
  178. });
  179. return SaveDialog;
  180. });