aboutsummaryrefslogtreecommitdiff
path: root/user-document-templates/montage-application-cloud/appdelegate.js
blob: 3c21b46eb39abe9dac80b31f1e826357b9bbdd63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/* <copyright>
This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
(c) Copyright 2011 Motorola Mobility, Inc.  All Rights Reserved.
</copyright> */

var Montage = require("montage/core/core").Montage,
    Component = require("montage/ui/component").Component;

exports.MyAppDelegate = Montage.create(Component, {
    templateDidLoad: {
		value: function(){
            window.addComponent = this.addComponentToUserDocument;
            window.addBinding = this.addBindingToUserDocument;

            var newEvent = document.createEvent( "CustomEvent" );
            newEvent.initCustomEvent( "userTemplateDidLoad", false, true );

            document.body.dispatchEvent( newEvent );

        }
    },

    addComponentToUserDocument:{
        value:function(containerElement, componentType){
            var component = null;
            switch(componentType){
                case "Button":
                    component = Button.create();
                    component.element = containerElement;
                    component.element.classList.add("text");
                    component.value = "Button";
                    component.needsDraw = true;
                    break;
                case "Checkbox":
                    component = Checkbox.create();
                    component.element = containerElement;
                    component.needsDraw = true;
                    break;
                case "Condition":
                    component = Condition.create();
                    component.element = containerElement;
                    component.needsDraw = true;
                    break;
                case "DynamicText":
                    component = DynamicText.create();
                    component.element = containerElement;
                    component.value = "Label";
                    component.needsDraw = true;
                    break;
                case "HotText":
                    component = HotText.create();
                    component.element = containerElement;
                    component.needsDraw = true;
                    break;
                case "HotTextUnit":
                    component = HotTextUnit.create();
                    component.element = containerElement;
                    component.needsDraw = true;
                    break;
                case "FlowController":
                    component = FlowController.create();
                    component.element = containerElement;
                    component.needsDraw = true;
                    break;
                case "ImageContainer":
                    component = ImageContainer.create();
                    component.element = containerElement;
                    component.element.style.width = "285px";
                    component.element.style.height = "235px";
                    component.src = "placeholder.jpg";
                    component.needsDraw = true;
                    break;
                case "Progress":
                    component = Progress.create();
                    component.element = containerElement;
                    component.loading = true;
                    component.needsDraw = true;
                    break;
                case "Repetition":
                    component = Repetition.create();
                    component.element = containerElement;
                    component.needsDraw = true;
                    break;
                case "Scrollview":
                    component = Scrollview.create();
                    component.element = containerElement;
                    component.element.style.width = "200px";
                    component.element.style.height = "200px";
                    var dummyContent = document.createElement("div");
                    dummyContent.innerHTML = "<img src='image3.jpg'/>";
                    component.element.appendChild(dummyContent);
                    component.needsDraw = true;
                    break;
                case "Slider":
                    component = Slider.create();
                    component.element = containerElement;
//                    component.value = 0;
//                    component._minValue = 0;
//                    component._maxValue = 100;
                    component.needsDraw = true;
                    break;
                case "Slot":
                    component = Slot.create();
                    component.element = containerElement;
                    component.needsDraw = true;
                    break;
                case "Substitution":
                    component = Substitution.create();
                    component.element = containerElement;
                    component.needsDraw = true;
                    break;
                case "TextArea":
                    component = TextArea.create();
                    component.element = containerElement;
                    component.needsDraw = true;
                    break;
                case "Textfield":
                    component = Textfield.create();
                    component.element = containerElement;
                    component.needsDraw = true;
                    break;
                case "Toggle":
                    component = Toggle.create();
                    component.element = containerElement;
                    component.needsDraw = true;
                    break;
                case "ToggleButton":
                    component = ToggleButton.create();
                    component.element = containerElement;
                    component.element.classList.add("text");
                    component.needsDraw = true;
                    break;
                default:
                    console.log("Unrecognized component type");
            }
            //console.log(component);
            return component;
        }
    },
    addBindingToUserDocument:{
        value:function(boundComponent, boundValue, targetComponent, targetValue){
            if(targetComponent[targetValue] != undefined && boundComponent[boundValue] != undefined){
                Object.defineBinding(boundComponent, boundValue, {
                    boundObject: targetComponent,
                    boundObjectPropertyPath: targetValue,
                    boundValueMutator: function(value) {
                        return(value);
                    }
                });
            } else {
                if(targetComponent[targetValue] == undefined){
                    console.log("Binding Fail - Component Property Not Found: " + targetValue);
                    alert("Binding Failed - Component Property Not Found: " + targetValue)
                } else if(boundComponent[boundValue] == undefined){
                    console.log("Binding Fail - Component Property Not Found: " + boundValue);
                    alert("Binding Failed - Component Property Not Found: " + boundValue);
                }
            }
        }
    }
});