aboutsummaryrefslogtreecommitdiff
path: root/js/mediators
diff options
context:
space:
mode:
Diffstat (limited to 'js/mediators')
-rwxr-xr-x[-rw-r--r--]js/mediators/drag-drop-mediator.js17
-rwxr-xr-x[-rw-r--r--]js/mediators/element-mediator.js34
-rw-r--r--js/mediators/io-mediator.js237
-rwxr-xr-x[-rw-r--r--]js/mediators/keyboard-mediator.js222
-rwxr-xr-x[-rw-r--r--]js/mediators/mouse-mediator.js0
5 files changed, 397 insertions, 113 deletions
diff --git a/js/mediators/drag-drop-mediator.js b/js/mediators/drag-drop-mediator.js
index ede71383..bf22aed2 100644..100755
--- a/js/mediators/drag-drop-mediator.js
+++ b/js/mediators/drag-drop-mediator.js
@@ -24,6 +24,10 @@ exports.DragDropMediator = Montage.create(Component, {
24 writable: true 24 writable: true
25 }, 25 },
26 26
27 dropDelegate: {
28 value: null
29 },
30
27 deserializedFromTemplate: { 31 deserializedFromTemplate: {
28 value: function() { 32 value: function() {
29 this.eventManager.addEventListener("appLoaded", this, false); 33 this.eventManager.addEventListener("appLoaded", this, false);
@@ -69,13 +73,14 @@ exports.DragDropMediator = Montage.create(Component, {
69 73
70 xferString = evt.dataTransfer.getData("text/plain"); 74 xferString = evt.dataTransfer.getData("text/plain");
71 if(xferString) { 75 if(xferString) {
72 76 // If the drop is a component, call the delegate with the top,left coordinates
73 if(xferString.lastIndexOf("-Component") !== -1) { 77 if(xferString.indexOf("componentDrop") > -1) {
74 component = xferString.substring(0, xferString.lastIndexOf("-Component")); 78 if(this.dropDelegate && typeof this.dropDelegate === 'object') {
75 NJevent( "executeAddComponent", { "component": component, "dropX": this.baseX, "dropY": this.baseY }); 79 this.dropDelegate.handleComponentDrop(this.baseX, this.baseY);
76// ComponentPanelModule.ComponentsPanelBase.addComponentToStage(componentStr.substring(0, compInd), this.baseX, this.baseY); 80 return;
81 }
77 } 82 }
78 return; 83
79 } 84 }
80 85
81 // Verify that browser supports FileReader API. 86 // Verify that browser supports FileReader API.
diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js
index 9aefbca6..51923f08 100644..100755
--- a/js/mediators/element-mediator.js
+++ b/js/mediators/element-mediator.js
@@ -28,13 +28,7 @@ exports.ElementMediator = Montage.create(NJComponent, {
28 // TODO use the specific controller to be able to subclass the functionality 28 // TODO use the specific controller to be able to subclass the functionality
29 handleElementAdding: { 29 handleElementAdding: {
30 value: function(event) { 30 value: function(event) {
31 /*
32 var cmd = ElementControllerCommands.addElementCommand(event.detail.el, event.detail.data);
33 NJevent("sendToUndo", cmd);
34 cmd.execute();
35 */
36 this.addElement(event.detail.el, event.detail.data); 31 this.addElement(event.detail.el, event.detail.data);
37
38 } 32 }
39 }, 33 },
40 34
@@ -97,17 +91,39 @@ exports.ElementMediator = Montage.create(NJComponent, {
97 value: function(el, rules, noEvent) { 91 value: function(el, rules, noEvent) {
98 ElementController.addElement(el, rules); 92 ElementController.addElement(el, rules);
99 var p3d = this.get3DProperties(el); 93 var p3d = this.get3DProperties(el);
100 if(p3d) 94 if(p3d) {
101 {
102 el.elementModel.controller["set3DProperties"](el, [p3d], 0, true); 95 el.elementModel.controller["set3DProperties"](el, [p3d], 0, true);
103 } 96 }
104 if(!noEvent) NJevent("elementAdded", el); 97 if(!noEvent) {
98 this.application.ninja.documentController.activeDocument.needsSave = true;
99 NJevent("elementAdded", el);
100 }
105 } 101 }
106 }, 102 },
107 103
104 deleteElements: {
105 value: function(items) {
106 // Add the Undo/Redo
107 var len, el;
108
109 len = items.length;
110
111 if(len) {
112
113 for(var i = len - 1; i >= 0; i--) {
114 el = items[i]._element || items[i];
115 this._removeElement(el);
116 }
117
118 NJevent( "deleteSelection", items );
119 }
120 }
121 },
122
108 _removeElement: { 123 _removeElement: {
109 value: function(el, rules) { 124 value: function(el, rules) {
110 ElementController.removeElement(el, rules); 125 ElementController.removeElement(el, rules);
126 this.application.ninja.documentController.activeDocument.needsSave = true;
111 NJevent("elementDeleted", el); 127 NJevent("elementDeleted", el);
112 } 128 }
113 }, 129 },
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js
new file mode 100644
index 00000000..56869839
--- /dev/null
+++ b/js/mediators/io-mediator.js
@@ -0,0 +1,237 @@
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 FileIo = require("js/io/system/fileio").FileIo,
12 ProjectIo = require("js/io/system/projectio").ProjectIo;
13////////////////////////////////////////////////////////////////////////
14//
15exports.IoMediator = Montage.create(Component, {
16 ////////////////////////////////////////////////////////////////////
17 //
18 hasTemplate: {
19 enumerable: false,
20 value: false
21 },
22 ////////////////////////////////////////////////////////////////////
23 //
24 deserializedFromTemplate: {
25 enumerable: false,
26 value: function () {
27 //
28 }
29 },
30 ////////////////////////////////////////////////////////////////////
31 //
32 fio: {
33 enumerable: false,
34 value: FileIo
35 },
36 ////////////////////////////////////////////////////////////////////
37 //
38 pio: {
39 enumerable: false,
40 value: ProjectIo
41 },
42 ////////////////////////////////////////////////////////////////////
43 //
44 fileNew: {
45 enumerable: false,
46 value: function (file, template, callback) {
47 //Loading template from template URL
48 var xhr = new XMLHttpRequest(), result;
49 xhr.open("GET", template, false);
50 xhr.send();
51 if (xhr.readyState === 4) {
52 //Making call to create file, checking for return code
53 switch (this.fio.newFile({uri: file, contents: xhr.response})) {
54 case 201:
55 result = {status: 201, success: true, uri: file};
56 break;
57 case 204:
58 result = {status: 204, success: false, uri: file};
59 break;
60 case 400:
61 result = {status: 400, success: false, uri: file};
62 break;
63 default:
64 result = {status: 500, success: false, uri: file};
65 break;
66 }
67 } else {
68 result = {status: 500, success: false, uri: file};
69 }
70 //Sending result to callback if requested for handling
71 if (callback) callback(result);
72 //Codes
73 // 204: File exists | 400: File exists
74 // 201: File succesfully created | 500: Unknown (Probably cloud API not running)
75 }
76 },
77 ////////////////////////////////////////////////////////////////////
78 //
79 fileOpen: {
80 enumerable: false,
81 value: function (file, callback) {
82 //Reading file (Ninja doesn't really open a file, all in browser memory)
83 var read = this.fio.readFile({uri: file}), result;
84 //Checking for status
85 switch(read.status) {
86 case 204:
87 //Creating and formatting result object for callbak
88 result = read.file.details;
89 result.root = read.file.details.uri.replace(read.file.details.name, "");
90 //Checking for type of content to returns
91 if (result.extension !== 'html' && result.extension !== 'htm') {
92 //Simple string
93 result.content = read.file.content;
94 } else {
95 //Object to be used by Ninja Template
96 result.content = this.parseHtmlToNinjaTemplate(read.file.content);
97 }
98 //Status of call
99 result.status = read.status;
100 //Calling back with result
101 if (callback) callback(result);
102 break;
103 case 404:
104 //File does not exists
105 if (callback) callback({status: read.status});
106 break;
107 default:
108 //Unknown
109 if (callback) callback({status: 500});
110 break;
111 }
112 /*
113 ////////////////////////////////////////////////////////////
114 ////////////////////////////////////////////////////////////
115 //Return Object Description
116 Object.status (Always presents for handling)
117 204: File exists (Success)
118 404: File does not exists (Failure)
119 500: Unknown (Probably cloud API not running)
120
121 (Below only present if succesfull 204)
122