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.js183
1 files changed, 92 insertions, 91 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js
index 1a8fec98..588481bb 100755
--- a/js/controllers/document-controller.js
+++ b/js/controllers/document-controller.js
@@ -1,24 +1,25 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility LLC.
3All Rights Reserved. 3All Rights Reserved.
4BSD License.
5 4
6Redistribution and use in source and binary forms, with or without 5Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met: 6modification, are permitted provided that the following conditions are met:
8 7
9 - Redistributions of source code must retain the above copyright notice, 8* Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer. 9 this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright 10
12 notice, this list of conditions and the following disclaimer in the 11* Redistributions in binary form must reproduce the above copyright notice,
13 documentation and/or other materials provided with the distribution. 12 this list of conditions and the following disclaimer in the documentation
14 - Neither the name of Motorola Mobility nor the names of its contributors 13 and/or other materials provided with the distribution.
15 may be used to endorse or promote products derived from this software 14
16 without specific prior written permission. 15* Neither the name of Motorola Mobility LLC nor the names of its
16 contributors may be used to endorse or promote products derived from this
17 software without specific prior written permission.
17 18
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
@@ -30,14 +31,14 @@ POSSIBILITY OF SUCH DAMAGE.
30 31
31//////////////////////////////////////////////////////////////////////// 32////////////////////////////////////////////////////////////////////////
32// 33//
33var Montage = require("montage/core/core").Montage, 34var Montage = require("montage/core/core").Montage,
34 Component = require("montage/ui/component").Component, 35 Component = require("montage/ui/component").Component,
35 HTMLDocument = require("js/document/document-html").HtmlDocument, 36 HTMLDocument = require("js/document/document-html").HtmlDocument,
36 TextDocument = require("js/document/document-text").TextDocument; 37 TextDocument = require("js/document/document-text").TextDocument;
37//////////////////////////////////////////////////////////////////////// 38////////////////////////////////////////////////////////////////////////
38// 39//
39exports.DocumentController = Montage.create(Component, { 40exports.DocumentController = Montage.create(Component, {
40 // 41 //
41 hasTemplate: { 42 hasTemplate: {
42 value: false 43 value: false
43 }, 44 },
@@ -110,45 +111,45 @@ exports.DocumentController = Montage.create(Component, {
110 } 111 }
111 }, 112 },
112 113
113 //TODO: Ensure these APIs are not needed 114 //TODO: Ensure these APIs are not needed
114 redirectRequests: { 115 redirectRequests: {
115 value: false 116 value: false
116 }, 117 },
117 //////////////////////////////////////////////////////////////////// 118 ////////////////////////////////////////////////////////////////////
118 // 119 //
119 handleWebRequest: { 120 handleWebRequest: {
120 value: function (request) { 121 value: function (request) {
121 //TODO: Check if frameId is proper 122 //TODO: Check if frameId is proper
122 if (this.redirectRequests && request.parentFrameId !== -1) { 123 if (this.redirectRequests && request.parentFrameId !== -1) {
123 //Checking for proper URL redirect (from different directories) 124 //Checking for proper URL redirect (from different directories)
124 if (request.url.indexOf('js/document/templates/banner') !== -1) { 125 if (request.url.indexOf('js/document/templates/banner') !== -1) {
125 return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/banner/'))[1]}; 126 return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/banner/'))[1]};
126 } else if (request.url.indexOf('js/document/templates/html') !== -1) { 127 } else if (request.url.indexOf('js/document/templates/html') !== -1) {
127 return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/html/'))[1]}; 128 return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/html/'))[1]};
128 } else if (request.url.indexOf('js/document/templates/app') !== -1) { 129 } else if (request.url.indexOf('js/document/templates/app') !== -1) {
129 return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/app/'))[1]}; 130 return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/app/'))[1]};
130 } else { 131 } else {
131 //Error, not a valid folder 132 //Error, not a valid folder
132 } 133 }
133 } 134 }
134 } 135 }
135 }, 136 },
136 //////////////////////////////////////////////////////////////////// 137 ////////////////////////////////////////////////////////////////////
137 // 138 //
138 handleAppLoaded: { 139 handleAppLoaded: {
139 value: function() { 140 value: function() {
140 //Checking for app to be loaded through extension 141 //Checking for app to be loaded through extension
141 var check; 142 var check;
142 if (chrome && chrome.app) { 143 if (chrome && chrome.app) {
143 check = chrome.app.getDetails(); 144 check = chrome.app.getDetails();
144 } 145 }
145 if (check !== null) { 146 if (check !== null) {
146 //Adding an intercept to resources loaded to ensure user assets load from cloud simulator 147 //Adding an intercept to resources loaded to ensure user assets load from cloud simulator
147 chrome.webRequest.onBeforeRequest.addListener(this.handleWebRequest.bind(this), {urls: ["<all_urls>"]}, ["blocking"]); 148 chrome.webRequest.onBeforeRequest.addListener(this.handleWebRequest.bind(this), {urls: ["<all_urls>"]}, ["blocking"]);
148 } 149 }
149 } 150 }
150 }, 151 },
151 //////////////////////////////////////////////////////////////////// 152 ////////////////////////////////////////////////////////////////////
152 153
153 154
154 handleExecuteFileOpen: { 155 handleExecuteFileOpen: {
@@ -172,39 +173,39 @@ exports.DocumentController = Montage.create(Component, {
172 } 173 }
173 } 174 }
174 }, 175 },
175 //////////////////////////////////////////////////////////////////// 176 ////////////////////////////////////////////////////////////////////
176 // 177 //
177 handleExecuteSave: { 178 handleExecuteSave: {
178 value: function(event) { 179 value: function(event) {
179 // 180 //
180 if((typeof this.currentDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ 181 if((typeof this.currentDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){
181 //Currently we don't need a callback handler 182 //Currently we don't need a callback handler
182 //this.activeDocument.model.save(this.saveExecuted.bind(this)); 183 //this.activeDocument.model.save(this.saveExecuted.bind(this));
183 this.currentDocument.model.save(); 184 this.currentDocument.model.save();
184 } else { 185 } else {
185 //Error: cloud not available and/or no active document 186 //Error: cloud not available and/or no active document
186 } 187 }
187 } 188 }
188 }, 189 },
189 //////////////////////////////////////////////////////////////////// 190 ////////////////////////////////////////////////////////////////////
190 // 191 //
191 saveExecuted: { 192 saveExecuted: {
192 value: function (value) { 193 value: function (value) {
193 //File saved, any callbacks or events should go here (must be added in handleExecuteSave passed as callback) 194 //File saved, any callbacks or events should go here (must be added in handleExecuteSave passed as callback)
194 } 195 }
195 }, 196 },
196 //////////////////////////////////////////////////////////////////// 197 ////////////////////////////////////////////////////////////////////
197 //TODO: Check for appropiate structures 198 //TODO: Check for appropiate structures
198 handleExecuteSaveAll: { 199 handleExecuteSaveAll: {
199 value: function(event) { 200 value: function(event) {
200 // 201 //
201 if((typeof this.currentDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ 202 if((typeof this.currentDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){
202 // 203 //
203 this.currentDocument.model.saveAll(); 204 this.currentDocument.model.saveAll();
204 } else { 205 } else {
205 //TODO: Add error handling 206 //TODO: Add error handling
206 } 207 }
207 } 208 }
208 }, 209 },
209 //////////////////////////////////////////////////////////////////// 210 ////////////////////////////////////////////////////////////////////
210 handleExecuteSaveAs: { 211 handleExecuteSaveAs: {
@@ -227,16 +228,16 @@ exports.DocumentController = Montage.create(Component, {
227 //////////////////////////////////////////////////////////////////// 228 ////////////////////////////////////////////////////////////////////
228 //TODO: Is this used, should be cleaned up 229 //TODO: Is this used, should be cleaned up
229 handleExecuteFileCloseAll:{ 230 handleExecuteFileCloseAll:{
230 value: function(event) { 231 value: function(event) {
231 if(this.currentDocument && this.application.ninja.coreIoApi.cloudAvailable()){ 232 if(this.currentDocument && this.application.ninja.coreIoApi.cloudAvailable()){
232 while(this.currentDocument.length > 0){ 233 while(this.currentDocument.length > 0){
233 this.closeDocument(this.currentDocument[this.currentDocument.length -1].uuid); 234 this.closeDocument(this.currentDocument[this.currentDocument.length -1].uuid);
234 } 235 }
235 } 236 }
236 } 237 }
237 }, 238 },
238 ////////////////////////////////////////////////////////////////////