aboutsummaryrefslogtreecommitdiff
path: root/js/controllers/document-controller.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/controllers/document-controller.js')
-rwxr-xr-xjs/controllers/document-controller.js50
1 files changed, 38 insertions, 12 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js
index fa611de4..77ae67a1 100755
--- a/js/controllers/document-controller.js
+++ b/js/controllers/document-controller.js
@@ -58,6 +58,8 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
58 this.eventManager.addEventListener("executeFileOpen", this, false); 58 this.eventManager.addEventListener("executeFileOpen", this, false);
59 this.eventManager.addEventListener("executeNewFile", this, false); 59 this.eventManager.addEventListener("executeNewFile", this, false);
60 this.eventManager.addEventListener("executeSave", this, false); 60 this.eventManager.addEventListener("executeSave", this, false);
61 this.eventManager.addEventListener("executeSaveAs", this, false);
62 this.eventManager.addEventListener("executeSaveAll", this, false);
61 63
62 this.eventManager.addEventListener("recordStyleChanged", this, false); 64 this.eventManager.addEventListener("recordStyleChanged", this, false);
63 65
@@ -102,33 +104,57 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
102 handleExecuteFileOpen: { 104 handleExecuteFileOpen: {
103 value: function(event) { 105 value: function(event) {
104 var pickerSettings = event._event.settings || {}; 106 var pickerSettings = event._event.settings || {};
105 pickerSettings.callback = this.openFileWithURI.bind(this); 107 if (this.application.ninja.coreIoApi.cloudAvailable()) {
106 pickerSettings.pickerMode = "read"; 108 pickerSettings.callback = this.openFileWithURI.bind(this);
107 pickerSettings.inFileMode = true; 109 pickerSettings.pickerMode = "read";
108 this.application.ninja.filePickerController.showFilePicker(pickerSettings); 110 pickerSettings.inFileMode = true;
111 this.application.ninja.filePickerController.showFilePicker(pickerSettings);
112 }
109 } 113 }
110 }, 114 },
111 115
112 handleExecuteNewFile: { 116 handleExecuteNewFile: {
113 value: function(event) { 117 value: function(event) {
114 var newFileSettings = event._event.settings || {}; 118 var newFileSettings = event._event.settings || {};
115 newFileSettings.callback = this.createNewFile.bind(this); 119 if (this.application.ninja.coreIoApi.cloudAvailable()) {
116 this.application.ninja.newFileController.showNewFileDialog(newFileSettings); 120 newFileSettings.callback = this.createNewFile.bind(this);
121 this.application.ninja.newFileController.showNewFileDialog(newFileSettings);
122 }
117 } 123 }
118 }, 124 },
119
120
121 //////////////////////////////////////////////////////////////////// 125 ////////////////////////////////////////////////////////////////////
122 //TODO: Check for appropiate structures 126 //TODO: Check for appropiate structures
123 handleExecuteSave: { 127 handleExecuteSave: {
124 value: function(event) { 128 value: function(event) {
125 if(!!this.activeDocument){ 129 if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){
126 //Text and HTML document classes should return the same save object for fileSave 130 //Text and HTML document classes should return the same save object for fileSave
127 this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this)); 131 this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this));
132 }
128 } 133 }
134 },
135 ////////////////////////////////////////////////////////////////////
136 //TODO: Check for appropiate structures
137 handleExecuteSaveAll: {
138 value: function(event) {
139 if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){
140 //Text and HTML document classes should return the same save object for fileSave
141 this.application.ninja.ioMediator.fileSave(this.activeDocument.saveAll(), this.fileSaveResult.bind(this));
142 }
129 } 143 }
130 }, 144 },
131 //////////////////////////////////////////////////////////////////// 145 ////////////////////////////////////////////////////////////////////
146 handleExecuteSaveAs: {
147 value: function(event) {
148 var saveAsSettings = event._event.settings || {};
149 if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){
150 saveAsSettings.fileName = this.activeDocument.name;
151 saveAsSettings.folderUri = this.activeDocument.uri.substring(0, this.activeDocument.uri.lastIndexOf("/"));
152 //add callback
153 this.application.ninja.newFileController.showSaveAsDialog(saveAsSettings);
154 }
155 }
156 },
157
132 // 158 //
133 fileSaveResult: { 159 fileSaveResult: {
134 value: function (result) { 160 value: function (result) {
@@ -287,7 +313,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
287 if(this.activeDocument.uuid === id && this._documents.length > 0) {//closing the active document tab 313 if(this.activeDocument.uuid === id && this._documents.length > 0) {//closing the active document tab
288 var nextDocumentIndex = -1 ; 314 var nextDocumentIndex = -1 ;
289 if((this._documents.length > 0) && (closeDocumentIndex === 0)){ 315 if((this._documents.length > 0) && (closeDocumentIndex === 0)){
290 nextDocumentIndex = 1; 316 nextDocumentIndex = 0;
291 }else if((this._documents.length > 0) && (closeDocumentIndex > 0)){ 317 }else if((this._documents.length > 0) && (closeDocumentIndex > 0)){
292 nextDocumentIndex = closeDocumentIndex - 1; 318 nextDocumentIndex = closeDocumentIndex - 1;
293 } 319 }