initial import(release): app plugin
[apps/native/blind-motor.git] / plugin / plugin / js / index.js
1 /*
2  * Copyright (c) 2015 - 2017 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17  var ocfDevice;
18  var className = "AirConditioner";
19  var capabilities = [capabilitySwitch, capabilityIlluminanceMeasurement, capabilityDoorControl];
20
21  window.onload = function () {
22         console.log("version : 0.0.1");
23         init();
24
25         document.body.addEventListener('click', function () {
26                 closeListBox();
27         })
28  };
29
30 function init() {
31         console.log("-----------init-----------");
32         scplugin.manager.getOCFDevices(getOCFDeviceCB);
33 }
34
35 function getOCFDeviceCB(devices) {
36         console.log("getOCFDeviceCB : " + devices.length);
37
38         for (var i in devices) {
39                 console.log("deviceHandle: " + devices[i].deviceHandle);
40                 console.log("deviceName: " + devices[i].deviceName);
41                 console.log("deviceType: " + devices[i].deviceType);
42                 console.log("metadata: " + devices[i].metadata);
43         }
44
45         setMainDevice(devices[0]);
46         ocfDevice.subscribe(onRepresentCallback);
47
48         for (var i = 0; i < capabilities.length; i++) {
49                 capabilities[i].update();
50         }
51 }
52
53 function onRepresentCallback(result, deviceHandle, uri, rcsJsonString) {
54         for (var i = 0; i < capabilities.length; i++) {
55                 if ( capabilities[i].href == uri) {
56                         capabilities[i].onRepresentCallback(result, deviceHandle, uri, rcsJsonString);
57                 }
58         }
59 }
60
61 function setMainDevice(device) {
62         scplugin.log.debug(className, arguments.callee.name, "set ocf device : " + device.deviceName);
63         ocfDevice = device;
64 }
65
66 function backAction() {
67         scplugin.manager.close();
68 }
69
70 function onPowerBtnClicked() {
71         capabilitySwitch.powerToggle();
72 }
73 /*
74 function checkAutoMode() {
75         if (autoModeBool = 1) {
76                 //checked;
77         }
78         else {
79         //unchecked;
80         }
81 }
82 */
83 function onSetBlindAutoModeClicked() {
84         if (capabilityDoorControl.autoControl == "false") {             //unchecked;
85                 if (capabilityDoorControl.doorState == "openState")     capabilityDoorControl.set("opening");
86                 else capabilityDoorControl.set("closing");
87                 capabilityDoorControl.autoControl = "true";     // true;
88 //              document.getElementById("autoMode").style.backgroundColor = "#3695dd";
89 //              document.getElementById("autoMode").style.color = "white";
90 //              document.getElementById("autoMode").style.borderColor = "#3695dd";
91 //              document.getElementById("autoMode").value = "AUTO ON"
92                 autoMode_on("on");
93         }
94         else {
95                 if (capabilityDoorControl.doorState == "openState") capabilityDoorControl.set("opened");
96                 else capabilityDoorControl.set("closed");
97                 capabilityDoorControl.autoControl = "false";
98                 autoMode_on("off");
99         //      document.getElementById("autoMode").style.backgroundColor = "white";
100 //              document.getElementById("autoMode").style.color = "#b4b4b4";
101 //              document.getElementById("autoMode").style.borderColor = "#b4b4b4";
102         //      document.getElementById("autoMode").value = "AUTO OFF"
103         }
104 }
105
106 function autoMode_on(onoff) {
107         var autoModeArea =      document.getElementById("autoMode");
108         if (onoff == "on") {
109                 autoModeArea.style.backgroundColor = "#3695dd";
110                 autoModeArea.style.color = "white";
111                 autoModeArea.style.borderColor = "#3695dd";
112                 autoModeArea.value = "AUTO ON";
113         } else {
114                 autoModeArea.style.backgroundColor = "white";
115                 autoModeArea.style.color = "#b4b4b4";
116                 autoModeArea.style.borderColor = "#b4b4b4";
117                 autoModeArea.value = "AUTO OFF";
118         }
119 }
120 //capabilityDoorControl.doorState == "closed" || capabilityDoorControl.doorState == "closed";
121 /*      document.getElementById("cancel_button").style.visibility = "hidden";  "visible";
122                                 document.getElementById("ready_text1").style.display = "inherit";
123                                 document.getElementById("ready_text2").style.display = "inherit";
124                                 document.getElementById("run_text1").style.display = "none";
125                                 document.getElementById("run_text2").style.display = "none";
126                                 document.getElementById("run_text3").style.display = "none";
127 */
128
129 function onSetBlindUpDnClicked(updnValue) {
130 // var pic;
131         var SelectedDoorState;
132          if (updnValue == 0) {
133                 capabilityDoorControl.set("closed");
134                 capabilityDoorControl.doorState = "closeState";
135         }
136         else {
137                 capabilityDoorControl.set("opened");
138                 capabilityDoorControl.doorState = "openState";
139         }
140 //      event.stopPropagation();
141 }
142
143 function blind_up_Action() {
144         capabilityDoorControl.blind_up_control();
145 }
146
147 function blind_dn_Action() {
148         capabilityDoorControl.blind_dn_control();
149 }
150
151 function blind_auto_Action() {
152         //      auto_button_toggle();
153         capabilityDoorControl.blind_auto_control();
154 }