aboutsummaryrefslogtreecommitdiff
path: root/js/controllers
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-02-20 11:14:44 -0800
committerNivesh Rajbhandari2012-02-20 11:14:44 -0800
commitabf78e2d7a97d295ce5a1c425fd359d47379137e (patch)
treed08c91bd2aef31e6325e0b499b2ffc390018bec6 /js/controllers
parente80a79bff57fecf3aa9b869d8ed2de5fd815287c (diff)
parente23708721a71ca4c71365f5f8e8ac7d6113926db (diff)
downloadninja-abf78e2d7a97d295ce5a1c425fd359d47379137e.tar.gz
Merge branch 'refs/heads/ninja-internal' into ToolFixes
Diffstat (limited to 'js/controllers')
-rwxr-xr-x[-rw-r--r--]js/controllers/color-controller.js0
-rwxr-xr-xjs/controllers/document-controller.js463
-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.js0
-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.js0
-rwxr-xr-x[-rw-r--r--]js/controllers/elements/video-controller.js0
-rwxr-xr-x[-rw-r--r--]js/controllers/local-storage-controller.js0
-rwxr-xr-x[-rw-r--r--]js/controllers/selection-controller.js0
-rwxr-xr-x[-rw-r--r--]js/controllers/styles-controller.js0
-rwxr-xr-x[-rw-r--r--]js/controllers/undo-controller.js0
15 files changed, 508 insertions, 0 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..1f339fe7
--- /dev/null
+++ b/js/controllers/document-controller.js
@@ -0,0 +1,463 @@
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 handleWebRequest: {
70 value: function (request) {
71 if (request.url.indexOf('js/document/templates/montage-html') !== -1) {
72
73 console.log(request);
74
75 //TODO: Figure out why active document is not available here
76
77 if (this._hackRootFlag) {
78
79 //console.log(request.url.split('/')[request.url.split('/').length-1]);
80 //console.log(this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController._activeDocument.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split('/')[request.url.split('/').length-1]);
81
82 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]};
83 }
84 }
85 }
86 },
87
88
89 handleAppLoaded: {
90 value: function() {
91 //
92
93 chrome.webRequest.onBeforeRequest.addListener(this.handleWebRequest.bind(this), {urls: ["<all_urls>"]}, ["blocking"]);
94
95 }
96 },
97
98 handleExecuteFileOpen: {
99 value: function(event) {
100 var pickerSettings = event._event.settings || {};
101 pickerSettings.callback = this.openFileWithURI.bind(this);
102 pickerSettings.pickerMode = "read";
103 pickerSettings.inFileMode = true;
104 this.application.ninja.filePickerController.showFilePicker(pickerSettings);
105 }
106 },
107
108 handleExecuteNewFile: {
109 value: function(event) {
110 var newFileSettings = event._event.settings || {};
111 newFileSettings.callback = this.createNewFile.bind(this);
112 this.application.ninja.newFileController.showNewFileDialog(newFileSettings);
113 }
114 },
115
116
117 ////////////////////////////////////////////////////////////////////
118 //TODO: Check for appropiate structures
119 handleExecuteSave: {
120 value: function(event) {
121 //Text and HTML document classes should return the same save object for fileSave
122 this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this));
123 }
124 },
125 ////////////////////////////////////////////////////////////////////
126 //
127 fileSaveResult: {
128 value: function (result) {
129 if(result.status === 204){
130 this.clearDocumentDirtyFlag();
131 }
132 }
133 },
134 ////////////////////////////////////////////////////////////////////
135
136
137 clearDocumentDirtyFlag:{
138 value: function(){
139 this.activeDocument.dirtyFlag = false;
140 }
141 },
142
143
144 createNewFile:{
145 value:function(newFileObj){
146 //console.log(newFileObj);//contains the template uri and the new file uri
147 if(!newFileObj) return;
148 this.application.ninja.ioMediator.fileNew(newFileObj.newFilePath, newFileObj.fileTemplateUri, this.openNewFileCallback.bind(this));
149
150 if((newFileObj.fileExtension !== ".html") && (newFileObj.fileExtension !== ".htm")){//open code view
151
152 } else {
153 //open design view
154 }
155 }
156 },
157
158 /**
159 * Public method
160 * doc contains:
161 * type : file type, like js, css, etc
162 * name : file name
163 * source : file content
164 * uri : file uri
165 */
166 openNewFileCallback:{
167 value:function(doc){
168 var response = doc || null;//default just for testing
169 if(!!response && response.success && (response.status!== 500) && !!response.uri){
170 this.application.ninja.ioMediator.fileOpen(response.uri, this.openFileCallback.bind(this));
171 }else if(!!response && !response.success){
172 //Todo: restrict directory path to the sandbox, in the dialog itself
173 alert("Unable to create file.\n [Error: Forbidden directory]");
174 }
175 }
176 },
177
178 openFileWithURI: {
179 value: function(uriArrayObj) {
180 var uri = "", fileContent = "", response=null, filename="", fileType="js";
181 if(!!uriArrayObj && !!uriArrayObj.uri && (uriArrayObj.uri.length > 0)){
182 uri = uriArrayObj.uri[0];
183 }
184 //console.log("URI is: ", uri);
185 if(!!uri){
186 this.application.ninja.ioMediator.fileOpen(uri, this.openFileCallback.bind(this));
187 }
188 }
189 },
190
191 ////////////////////////////////////////////////////////////////////
192 //
193 openFileCallback:{
194 value:function(response){
195 //TODO: Add UI to handle error codes, shouldn't be alert windows