aboutsummaryrefslogtreecommitdiff
path: root/js/controllers
diff options
context:
space:
mode:
authorArmen Kesablyan2012-02-22 16:26:41 -0800
committerArmen Kesablyan2012-02-22 16:26:41 -0800
commit0bd1cefea2ab350fad1a891bdc926053b799aafc (patch)
tree962f559fcc02a3dfeb297d59907e40fa153453f3 /js/controllers
parent695bc5082f48dddf66ce31480a4faefc067b38bd (diff)
parent2d2b1af8b5c0d506fe6a1cf65614101fec145970 (diff)
downloadninja-0bd1cefea2ab350fad1a891bdc926053b799aafc.tar.gz
Merge branch 'refs/heads/master' into new-tool-icons
Diffstat (limited to 'js/controllers')
-rwxr-xr-x[-rw-r--r--]js/controllers/color-controller.js0
-rwxr-xr-xjs/controllers/document-controller.js462
-rwxr-xr-x[-rw-r--r--]js/controllers/elements/block-controller.js0
-rwxr-xr-x[-rw-r--r--]js/controllers/elements/canvas-controller.js0
-rwxr-xr-x[-rw-r--r--]js/controllers/elements/component-controller.js44
-rwxr-xr-x[-rw-r--r--]js/controllers/elements/controller-factory.js0
-rwxr-xr-x[-rw-r--r--]js/controllers/elements/element-controller.js3
-rwxr-xr-x[-rw-r--r--]js/controllers/elements/image-controller.js0
-rwxr-xr-x[-rw-r--r--]js/controllers/elements/shapes-controller.js1
-rwxr-xr-x[-rw-r--r--]js/controllers/elements/stage-controller.js4
-rwxr-xr-x[-rw-r--r--]js/controllers/elements/video-controller.js0
-rwxr-xr-x[-rw-r--r--]js/controllers/local-storage-controller.js0
-rw-r--r--js/controllers/main-menu-controller.js6
-rwxr-xr-x[-rw-r--r--]js/controllers/selection-controller.js36
-rwxr-xr-x[-rw-r--r--]js/controllers/styles-controller.js7
-rwxr-xr-x[-rw-r--r--]js/controllers/undo-controller.js0
16 files changed, 553 insertions, 10 deletions
diff --git a/js/controllers/color-controller.js b/js/controllers/color-controller.js
index e3b15f1c..e3b15f1c 100644..100755
--- a/js/controllers/color-controller.js
+++ b/js/controllers/color-controller.js
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js
new file mode 100755
index 00000000..fa611de4
--- /dev/null
+++ b/js/controllers/document-controller.js
@@ -0,0 +1,462 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7////////////////////////////////////////////////////////////////////////
8//
9var Montage = require("montage/core/core").Montage,
10 Component = require("montage/ui/component").Component,
11 Uuid = require("montage/core/uuid").Uuid,
12 HTMLDocument = require("js/document/html-document").HTMLDocument,
13 TextDocument = require("js/document/text-document").TextDocument,
14 DocumentController;
15////////////////////////////////////////////////////////////////////////
16//
17var DocumentController = exports.DocumentController = Montage.create(Component, {
18 hasTemplate: {
19 value: false
20 },
21
22 _documents: {
23 value: []
24 },
25
26 _hackRootFlag: {
27 value: false
28 },
29
30 _activeDocument: { value: null },
31 _iframeCounter: { value: 1, enumerable: false },
32 _iframeHolder: { value: null, enumerable: false },
33 _textHolder: { value: null, enumerable: false },
34 _codeMirrorCounter: {value: 1, enumerable: false},
35
36 activeDocument: {
37 get: function() {
38 return this._activeDocument;
39 },
40 set: function(doc) {
41 if(!!this._activeDocument) this._activeDocument.isActive = false;
42
43 this._activeDocument = doc;
44 if(!!this._activeDocument){
45
46 if(this._documents.indexOf(doc) === -1) this._documents.push(doc);
47 this._activeDocument.isActive = true;
48 if(!!this._activeDocument.editor){
49 this._activeDocument.editor.focus();
50 }
51 }
52 }
53 },
54
55 deserializedFromTemplate: {
56 value: function() {
57 this.eventManager.addEventListener("appLoaded", this, false);
58 this.eventManager.addEventListener("executeFileOpen", this, false);
59 this.eventManager.addEventListener("executeNewFile", this, false);
60 this.eventManager.addEventListener("executeSave", this, false);
61
62 this.eventManager.addEventListener("recordStyleChanged", this, false);
63
64 }
65 },
66
67
68
69
70
71
72
73 ////////////////////////////////////////////////////////////////////
74 //
75 handleWebRequest: {
76 value: function (request) {
77 if (this._hackRootFlag && request.url.indexOf('js/document/templates/montage-html') !== -1) {
78 //TODO: Optimize creating string
79 return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split('/')[request.url.split('/').length-1]};
80 }
81 }
82 },
83 ////////////////////////////////////////////////////////////////////
84 //
85 handleAppLoaded: {
86 value: function() {
87 //Adding an intercept to resources loaded to ensure user assets load from cloud simulator
88 if (window.chrome.app.isInstalled) {
89 chrome.webRequest.onBeforeRequest.addListener(this.handleWebRequest.bind(this), {urls: ["<all_urls>"]}, ["blocking"]);
90 }
91 }
92 },
93 ////////////////////////////////////////////////////////////////////
94
95
96
97
98
99
100
101
102 handleExecuteFileOpen: {
103 value: function(event) {
104 var pickerSettings = event._event.settings || {};
105 pickerSettings.callback = this.openFileWithURI.bind(this);
106 pickerSettings.pickerMode = "read";
107 pickerSettings.inFileMode = true;
108 this.application.ninja.filePickerController.showFilePicker(pickerSettings);
109 }
110 },
111
112 handleExecuteNewFile: {
113 value: function(event) {
114 var newFileSettings = event._event.settings || {};
115 newFileSettings.callback = this.createNewFile.bind(this);
116 this.application.ninja.newFileController.showNewFileDialog(newFileSettings);
117 }
118 },
119
120
121 ////////////////////////////////////////////////////////////////////
122 //TODO: Check for appropiate structures
123 handleExecuteSave: {
124 value: function(event) {
125 if(!!this.activeDocument){
126 //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));
128 }
129 }
130 },
131 ////////////////////////////////////////////////////////////////////
132 //
133 fileSaveResult: {
134 value: function (result) {
135 if(result.status === 204){
136 this.activeDocument.needsSave = false;
137 }
138 }
139 },
140
141 createNewFile:{
142 value:function(newFileObj){
143 //console.log(newFileObj);//contains the template uri and the new file uri
144 if(!newFileObj) return;
145 this.application.ninja.ioMediator.fileNew(newFileObj.newFilePath, newFileObj.fileTemplateUri, this.openNewFileCallback.bind(this));
146
147 if((newFileObj.fileExtension !== ".html") && (newFileObj.fileExtension !== ".htm")){//open code view
148
149 } else {
150 //open design view
151 }
152 }
153 },
154
155 /**
156 * Public method
157 * doc contains:
158 * type : file type, like js, css, etc
159 * name : file name
160 * source : file content
161 * uri : file uri
162 */
163 openNewFileCallback:{
164 value:function(doc){
165 var response = doc || null;//default just for testing
166 if(!!response && response.success && (response.status!== 500) && !!response.uri){
167 this.application.ninja.ioMediator.fileOpen(response.uri, this.openFileCallback.bind(this));
168 }else if(!!response && !response.success){
169 //Todo: restrict directory path to the sandbox, in the dialog itself
170 alert("Unable to create file.\n [Error: Forbidden directory]");
171 }
172 }
173 },
174
175 openFileWithURI: {
176 value: function(uriArrayObj) {
177 var uri = "", fileContent = "", response=null, filename="", fileType="js";
178 if(!!uriArrayObj && !!uriArrayObj.uri && (uriArrayObj.uri.length > 0)){
179 uri = uriArrayObj.uri[0];
180 }
181 //console.log("URI is: ", uri);
182 if(!!uri){
183 this.application.ninja.ioMediator.fileOpen(uri, this.openFileCallback.bind(this));
184 }
185 }
186 },
187
188 ////////////////////////////////////////////////////////////////////
189 //
190 openFileCallback:{
191 value:function(response){
192 //TODO: Add UI to handle error codes, shouldn't be alert windows
193 if(!!response && (response.status === 204)) {
194