diff options
author | Jose Antonio Marquez | 2012-02-15 20:37:48 -0800 |
---|---|---|
committer | Jose Antonio Marquez | 2012-02-15 20:37:48 -0800 |
commit | 89b5e793ea88ef235b54b6e1d1c379698d3e612b (patch) | |
tree | 4d29118f35df77ca6b423119a4ff61694a442cbf /js/controllers | |
parent | 9d2c2a80483415d7560b00cda5519153db23e241 (diff) | |
parent | d366c0bd1af6471511217ed574083e15059519b5 (diff) | |
download | ninja-89b5e793ea88ef235b54b6e1d1c379698d3e612b.tar.gz |
Merge branch 'refs/heads/NinjaInternal' into Color
Diffstat (limited to 'js/controllers')
16 files changed, 555 insertions, 8 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..84b994ce --- /dev/null +++ b/js/controllers/document-controller.js | |||
@@ -0,0 +1,430 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No 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 | // | ||
9 | var Montage = require("montage/core/core").Montage, | ||
10 | Component = require("montage/ui/component").Component, | ||
11 | Uuid = require("montage/core/uuid").Uuid, | ||
12 | HTMLDocument = require("js/io/document/html-document").HTMLDocument, | ||
13 | TextDocument = require("js/io/document/text-document").TextDocument, | ||
14 | DocumentController; | ||
15 | //////////////////////////////////////////////////////////////////////// | ||
16 | // | ||
17 | DocumentController = exports.DocumentController = Montage.create(Component, { | ||
18 | hasTemplate: { | ||
19 | value: false | ||
20 | }, | ||
21 | |||
22 | _documents: { | ||
23 | value: [] | ||
24 | }, | ||
25 | |||
26 | _activeDocument: { value: null }, | ||
27 | _iframeCounter: { value: 1, enumerable: false }, | ||
28 | _iframeHolder: { value: null, enumerable: false }, | ||
29 | _textHolder: { value: null, enumerable: false }, | ||
30 | _codeMirrorCounter: {value: 1, enumerable: false}, | ||
31 | |||
32 | tmpSourceForTesting: { | ||
33 | value: "function CodeMirror(place, givenOptions) {" + | ||
34 | "// Determine effective options based on given values and defaults." + | ||
35 | "var options = {}, defaults = CodeMirror.defaults; }" | ||
36 | }, | ||
37 | |||
38 | activeDocument: { | ||
39 | get: function() { | ||
40 | return this._activeDocument; | ||
41 | }, | ||
42 | set: function(doc) { | ||
43 | if(this._activeDocument) this._activeDocument.isActive = false; | ||
44 | |||
45 | if(this._documents.indexOf(doc) === -1) this._documents.push(doc); | ||
46 | |||
47 | this._activeDocument = doc; | ||
48 | this._activeDocument.isActive = true; | ||
49 | |||
50 | if(!!this._activeDocument.editor){ | ||
51 | this._activeDocument.editor.focus(); | ||
52 | } | ||
53 | |||
54 | } | ||
55 | }, | ||
56 | |||
57 | deserializedFromTemplate: { | ||
58 | value: function() { | ||
59 | this.eventManager.addEventListener("appLoaded", this, false); | ||
60 | this.eventManager.addEventListener("executeFileOpen", this, false); | ||
61 | this.eventManager.addEventListener("executeNewFile", this, false); | ||
62 | this.eventManager.addEventListener("executeSave", this, false); | ||
63 | |||
64 | this.eventManager.addEventListener("recordStyleChanged", this, false); | ||
65 | |||
66 | // Temporary testing opening a new file after Ninja has loaded | ||
67 | this.eventManager.addEventListener("executeNewProject", this, false); | ||
68 | } | ||
69 | }, | ||
70 | |||
71 | handleAppLoaded: { | ||
72 | value: function() { | ||
73 | //this.openDocument({"type": "html"}); | ||
74 | } | ||
75 | }, | ||
76 | |||
77 | handleExecuteNewProject: { | ||
78 | value: function() { | ||
79 | this.openDocument({"type": "html"}); | ||
80 | } | ||
81 | }, | ||
82 | |||
83 | handleExecuteFileOpen: { | ||
84 | value: function(event) { | ||
85 | var pickerSettings = event._event.settings || {}; | ||
86 | pickerSettings.callback = this.openFileWithURI.bind(this); | ||
87 | pickerSettings.pickerMode = "read"; | ||
88 | pickerSettings.inFileMode = true; | ||
89 | this.application.ninja.filePickerController.showFilePicker(pickerSettings); | ||
90 | } | ||
91 | }, | ||
92 | |||
93 | handleExecuteNewFile: { | ||
94 | value: function(event) { | ||
95 | var newFileSettings = event._event.settings || {}; | ||
96 | newFileSettings.callback = this.createNewFile.bind(this); | ||
97 | this.application.ninja.newFileController.showNewFileDialog(newFileSettings); | ||
98 | } | ||
99 | }, | ||
100 | |||
101 | |||
102 | //////////////////////////////////////////////////////////////////// | ||
103 | //TODO: Check for appropiate structures | ||
104 | handleExecuteSave: { | ||
105 | value: function(event) { | ||
106 | //Text and HTML document classes should return the same save object for fileSave | ||
107 | this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.clearDocumentDirtyFlag.bind(this)); | ||
108 | } | ||
109 | }, | ||
110 | |||
111 | clearDocumentDirtyFlag:{ | ||
112 | value: function(){ | ||
113 | this.activeDocument.dirtyFlag = false; | ||
114 | } | ||
115 | }, | ||
116 | //////////////////////////////////////////////////////////////////// | ||
117 | |||
118 | |||
119 | createNewFile:{ | ||
120 | value:function(newFileObj){ | ||
121 | //console.log(newFileObj);//contains the template uri and the new file uri | ||
122 | if(!newFileObj) return; | ||
123 | this.application.ninja.ioMediator.fileNew(newFileObj.newFilePath, newFileObj.fileTemplateUri, this.openNewFileCallback.bind(this)); | ||
124 | |||
125 | if((newFileObj.fileExtension !== ".html") && (newFileObj.fileExtension !== ".htm")){//open code view | ||
126 | |||
127 | } else { | ||
128 | //open design view | ||
129 | } | ||
130 | } | ||
131 | }, | ||
132 | |||
133 | /** | ||
134 | * Public method | ||
135 | * doc contains: | ||
136 | * type : file type, like js, css, etc | ||
137 | * name : file name | ||
138 | * source : file content | ||
139 | * uri : file uri | ||
140 | */ | ||
141 | openNewFileCallback:{ | ||
142 | value:function(doc){ | ||
143 | var response = doc || null;//default just for testing | ||
144 | if(!!response && response.success && (response.status!== 500) && !!response.uri){ | ||
145 | this.application.ninja.ioMediator.fileOpen(response.uri, this.openFileCallback.bind(this)); | ||
146 | }else if(!!response && !response.success){ | ||
147 | //Todo: restrict directory path to the sandbox, in the dialog itself | ||
148 | alert("Unable to create file.\n [Error: Forbidden directory]"); | ||
149 | } | ||
150 | } | ||
151 | }, | ||
152 | |||
153 | openFileWithURI: { | ||
154 | value: function(uriArrayObj) { | ||
155 | var uri = "", fileContent = "", response=null, filename="", fileType="js"; | ||
156 | if(!!uriArrayObj && !!uriArrayObj.uri && (uriArrayObj.uri.length > 0)){ | ||
157 | uri = uriArrayObj.uri[0]; | ||
158 | } | ||
159 | //console.log("URI is: ", uri); | ||
160 | if(!!uri){ | ||
161 | this.application.ninja.ioMediator.fileOpen(uri, this.openFileCallback.bind(this)); | ||
162 | } | ||
163 | } | ||
164 | }, | ||
165 | |||
166 | //////////////////////////////////////////////////////////////////// | ||
167 | // | ||
168 | openFileCallback:{ | ||
169 | value:function(response){ | ||
170 | //TODO: Add UI to handle error codes, shouldn't be alert windows | ||
171 | if(!!response && (response.status === 204)) { | ||
172 | //Sending full response object | ||
173 | this.openDocument(response); | ||
174 | } else if (!!response && (response.status === 404)){ | ||
175 | alert("Unable to open file.\n [Error: File does not exist]"); | ||
176 | } else if (!!response && (response.status === 500)){ | ||
177 | alert("Unable to open file.\n Check if Ninja Local Cloud is running."); | ||
178 | } else{ | ||
179 | alert("Unable to open file."); | ||
180 | } | ||
181 | |||
182 | } | ||
183 | }, | ||
184 | //////////////////////////////////////////////////////////////////// | ||
185 | // | ||
186 | openDocument: { | ||
187 | value: function(doc) { | ||
188 | // | ||
189 | switch (doc.extension) { | ||
190 | case 'html': case 'html': | ||
191 | //Open in designer view | ||
192 | Montage.create(HTMLDocument).initialize(doc, Uuid.generate(), this._createIframeElement(), this._onOpenDocument); | ||
193 | break; | ||
194 | default: | ||
195 | //Open in code view | ||