1 /* 2 * This is time cordova_plugin (TV specific API). 3 * Apache License (2004). See http://www.apache.org/licenses/LICENSE-2.0 4 * 5 * Copyright (c) 2014, LG Electronics, Inc. 6 */ 7 8 /** 9 * This represents the time API itself, and provides a global namespace for operating time service. 10 * @class 11 */ 12 cordova.define('cordova/plugin/time', function (require, exports, module) { // jshint ignore:line 13 14 function log(msg) { 15 // //console.log//will be removed // jshint ignore:line 16 } 17 18 var service; 19 if (window.PalmSystem) { // jshint ignore:line 20 log("Window.PalmSystem Available"); 21 service = require('cordova/plugin/webos/service'); 22 } else { 23 service = { 24 Request : function(uri, params) { 25 log(uri + " invoked. But I am a dummy because PalmSystem is not available"); 26 27 if (typeof params.onFailure === 'function') { 28 params.onFailure({ 29 returnValue:false, 30 errorText:"PalmSystem Not Available. Cordova is not installed?" 31 }); 32 } 33 }}; 34 } 35 36 /** 37 * time interface 38 */ 39 var Time = function () { 40 }; 41 42 function checkErrorCodeNText(result, errorCode, errorText) { 43 44 if (result.errorCode === undefined || result.errorCode === null ) { 45 result.errorCode = errorCode; 46 } 47 if (result.errorText ===undefined || result.errorText === null) { 48 result.errorText = errorText; 49 } 50 } 51 52 var version = null; 53 var platformInfoObj = {}; 54 function checkPlatformVersion(cb) { 55 56 if (version === null) { 57 58 service.Request('luna://com.webos.service.tv.systemproperty', { 59 method: 'getSystemInfo', 60 parameters: { 61 keys: ["sdkVersion", "boardType"] 62 }, 63 onSuccess: function(result) { 64 log("getPlatformInfo: onSuccess"); 65 log("version : " + result.sdkVersion); 66 67 var temp = result.sdkVersion.split('.'); 68 if (temp.length >= 1 && temp[0] === '1') { 69 platformInfoObj = { 70 webOSVer: 1, 71 chipset: result.boardType.split("_")[0] 72 }; 73 } else if (temp.length >= 1 && temp[0] === '2') { 74 platformInfoObj = { 75 webOSVer: 2, 76 chipset: result.boardType.split("_")[0] 77 }; 78 } else if (temp.length >= 1 && temp[0] === '3') { 79 platformInfoObj = { 80 webOSVer: 3, 81 chipset: result.boardType.split("_")[0] 82 }; 83 } else { 84 platformInfoObj = { 85 webOSVer: 0, 86 chipset: "" 87 }; 88 } 89 version = platformInfoObj.webOSVer; 90 cb(platformInfoObj); 91 }, 92 onFailure: function(error) { 93 log("getPlatformInfo: onFailure"); 94 platformInfoObj = { 95 webOSVer: 0, 96 chipset: "" 97 } 98 cb(platformInfoObj); 99 } 100 }); 101 102 } else { 103 cb(platformInfoObj); 104 } 105 } 106 107 /** 108 * set HolidayScheduleMode enabled/disabled 109 * @class Time 110 * @param {Function} successCallback success callback function. 111 * @param {Function} errorCallback failure callback function. 112 * @param {Object} options 113 * <div align=left> 114 * <table class="hcap_spec" width=400> 115 * <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead> 116 * <tbody> 117 * <tr><th>enabled</th><th>Boolean</th><th>Intelligent auto is enabled. true: enabled, false: disabled</th><th>required</th></tr> 118 * </tbody> 119 * </table> 120 * </div> 121 * @return <p>If the method is successfully executed, call the success callback function without a parameter.</br> 122 * If an error occurs, failure callback function is called with failure callback object as a parameter.</p> 123 * @example 124 * // Javascript code 125 * 126 * function setHolidayScheduleMode () { 127 * var options = { 128 * enabled : true 129 * }; 130 * 131 * function successCb() { 132 * // Do something 133 * } 134 * 135 * function failureCb(cbObject) { 136 * var errorCode = cbObject.errorCode; 137 * var errorText = cbObject.errorText; 138 * console.log ("Error Code [" + errorCode + "]: " + errorText); 139 * } 140 * 141 * var time = new Time(); 142 * time.setHolidayScheduleMode(successCb, failureCb, options); 143 * } 144 * @since 1.4 145 * @see 146 * <a href="Time%23getHolidayScheduleMode.html">Time.getHolidayScheduleMode()</a><br> 147 */ 148 Time.prototype.setHolidayScheduleMode = function (successCallback, errorCallback, options) { 149 log("setHolidayScheduleMode: " + options.enabled); 150 151 var ret = { }; 152 checkErrorCodeNText(ret, "ERROR", "This function is not supported on webOS 3.2"); 153 errorCallback(ret); 154 return; 155 156 if (options.enabled === null && typeof errorCallback === 'function') { 157 var result = {}; 158 checkErrorCodeNText(result, "TSHM", "Time.setHolidayScheduleMode returns failure. command was not defined."); 159 errorCallback(result); 160 log("Time.setHolidayScheduleMode invalid "); 161 return; 162 } 163 164 service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", { 165 method : "set", 166 parameters : { 167 category : "commercial", 168 settings : { 169 "holidayScheduleMode" : (options.enabled === true ) ? "on" : "off" 170 } 171 }, 172 onSuccess : function(result) { 173 log("setHolidayScheduleMode: On Success"); 174 175 if (result.returnValue === true) { 176 if(typeof successCallback === 'function') { 177 successCallback(); 178 } 179 } 180 }, 181 onFailure : function(result) { 182 log("setHolidayScheduleMode: On Failure"); 183 delete result.returnValue; 184 if (typeof errorCallback === 'function') { 185 checkErrorCodeNText(result, "TSHM", "Time.setHolidayScheduleMode returns failure."); 186 errorCallback(result); 187 } 188 } 189 }); 190 191 log("Time.setHolidayScheduleMode Done"); 192 }; 193 194 /** 195 * Gets HolidayScheduleMode enabled 196 * @class Time 197 * @param {Function} successCallback success callback function. 198 * @param {Function} errorCallback failure callback function. 199 * @return {Object} 200 * <div align=left> 201 * <table class="hcap_spec" width=400> 202 * <thead><tr><th>Property</th><th>Type</th><th>Description</th></tr></thead> 203 * <tbody> 204 * <tr><th>enabled</th><th>Boolean</th><th>Intelligent auto is enabled. true: enabled, false: disabled</th></tr> 205 * </tbody> 206 * </table> 207 * </div> 208 * 209 * @example 210 * // Javascript code 211 * function getHolidayScheduleMode () { 212 * function successCb(cbObject) { 213 * console.log("cbObject : " + JSON.stringify(cbObject)); 214 * 215 * console.log("enabled : " + cbObject.enabled); 216 * 217 * // Do something 218 * ... 219 * } 220 * 221 * function failureCb(cbObject) { 222 * var errorCode = cbObject.errorCode; 223 * var errorText = cbObject.errorText; 224 * console.log ("Error Code [" + errorCode + "]: " + errorText); 225 * } 226 * 227 * var time = new Time(); 228 * time.getHolidayScheduleMode(successCb, failureCb); 229 * } 230 * @since 1.4 231 * @see 232 * <a href="Time%23setHolidayScheduleMode.html">Time.setHolidayScheduleMode()</a><br> 233 */ 234 Time.prototype.getHolidayScheduleMode = function (successCallback, errorCallback) { 235 236 log("getHolidayScheduleMode: "); 237 238 var ret = { }; 239 checkErrorCodeNText(ret, "ERROR", "This function is not supported on webOS 3.2"); 240 errorCallback(ret); 241 return; 242 243 service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", { 244 method: "get", 245 parameters: { 246 category: "commercial", 247 keys: ["holidayScheduleMode"] 248 }, 249 onSuccess: function(result) { 250 log("getHolidayScheduleMode: On Success"); 251 252 if (result.returnValue === true) { 253 var cbObj = {}; 254 cbObj.enabled = (result.settings.holidayScheduleMode === "on") ? true : false; 255 256 if (typeof successCallback === 'function') { 257 successCallback(cbObj); 258 } 259 } 260 }, 261 onFailure: function(result) { 262 log("getHolidayScheduleMode: On Failure"); 263 delete result.returnValue; 264 if (typeof errorCallback === 'function') { 265 checkErrorCodeNText(result, "TGHM", "Time.getHolidayScheduleMode returns failure."); 266 errorCallback(result); 267 } 268 } 269 }); 270 271 log("Time.getHolidayScheduleMode Done"); 272 }; 273 274 /** 275 * add HolidaySchedule 276 * @class Time 277 * @param {Function} successCallback success callback function. 278 * @param {Function} errorCallback failure callback function. 279 * @param {Object} options 280 * <div align=left> 281 * <table class="hcap_spec" width=400> 282 * <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead> 283 * <tbody> 284 * <tr><th>startMonth</th><th>Number</th><th>start month</th><th>required</th></tr> 285 * <tr class="odd"><th>startDay</th><th>Number</th><th>start day</th><th>required</th></tr> 286 * <tr><th>endMonth</th><th>Number</th><th>end month</th><th>required</th></tr> 287 * <tr class="odd"><th>endDay</th><th>Number</th><th>end day</th><th>required</th></tr> 288 * </tbody> 289 * </table> 290 * </div> 291 * @return <p>If the method is successfully executed, call the success callback function without a parameter.</br> 292 * If an error occurs, failure callback function is called with failure callback object as a parameter.</p> 293 * @example 294 * // Javascript code 295 * 296 * function addHolidaySchedule () { 297 * var options = { 298 * startMonth : 3, 299 * startDay : 7, 300 * endMonth : 3, 301 * endDay : 9 //ex. 3/7~3/9 302 * }; 303 * 304 * function successCb() { 305 * // Do something 306 * } 307 * 308 * function failureCb(cbObject) { 309 * var errorCode = cbObject.errorCode; 310 * var errorText = cbObject.errorText; 311 * console.log ("Error Code [" + errorCode + "]: " + errorText); 312 * } 313 * 314 * var time = new Time(); 315 * time.addHolidaySchedule(successCb, failureCb, options); 316 * } 317 * @since 1.4 318 * @see 319 * <a href="Time%23getHolidayScheduleMode.html">Time.getHolidayScheduleMode()</a><br> 320 */ 321 Time.prototype.addHolidaySchedule = function (successCallback, errorCallback, options) { 322 log("addHolidaySchedule: " + "startMonth : " + options.startMonth + ", startDay : " + options.startDay + ", endMonth : " + options.endMonth + ", endDay : " + options.endDay); 323 324 var ret = { }; 325 checkErrorCodeNText(ret, "ERROR", "This function is not supported on webOS 3.2"); 326 errorCallback(ret); 327 return; 328 329 var startSch = new Date((new Date()).getFullYear(), options.startMonth-1, options.startDay, 0, 0); 330 var endSch = new Date((new Date()).getFullYear(), options.endMonth-1, options.endDay, 0, 0); 331 332 //validation check 333 if (typeof errorCallback === 'function') { 334 if (typeof options.startMonth !== 'number' || typeof options.startDay !== 'number' || isNaN(options.startMonth) || isNaN(options.startDay) || 335 typeof options.endMonth !== 'number' || typeof options.endDay !== 'number' || isNaN(options.endMonth) || isNaN(options.endDay)) { 336 var result = {}; 337 checkErrorCodeNText(result, "TAHS", "Time.addHolidaySchedule returns failure. parmas are not valid."); 338 errorCallback(result); 339 return; 340 } 341 342 if (startSch.getMonth() !== options.startMonth - 1 || startSch.getDate() !== options.startDay || 343 endSch.getMonth() !== options.endMonth - 1 || endSch.getDate() !== options.endDay) { 344 var result = {}; 345 checkErrorCodeNText(result, "TAHS", "Time.addHolidaySchedule returns failure for out of range."); 346 errorCallback(result); 347 return; 348 } 349 350 if (startSch.getTime() > endSch.getTime()) 351 { 352 var result = {}; 353 checkErrorCodeNText(result, "TAHS", "Time.addHolidaySchedule returns failure. schedule is not valid."); 354 errorCallback(result); 355 return; 356 } 357 } 358 359 service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", { 360 method : "get", 361 parameters : { 362 category : "commercial", 363 keys : ["holidaySchedule"] 364 }, 365 onSuccess : function(result) { 366 log("getHolidaySchedule: On Success"); 367 368 if (result.returnValue === true) { 369 if (typeof successCallback === 'function') { 370 var schedule = {}; 371 var savedStartSch = null 372 var savedEndSch = null 373 var scheduleList = result.settings.holidaySchedule; 374 375 if(scheduleList.length >= 7) 376 { 377 var result = {}; 378 checkErrorCodeNText(result, "TAHS", "Time.addHolidaySchedule returns failure. schedule list is full"); 379 errorCallback(result); 380 return; 381 } 382 383 //check same schedule 384 for(var i=0; i<scheduleList.length; i++) { 385 386 savedStartSch = new Date((new Date()).getFullYear(), scheduleList[i].startMonth - 1, scheduleList[i].startDay, 0, 0); 387 savedEndSch = new Date((new Date()).getFullYear(), scheduleList[i].endMonth - 1, scheduleList[i].endDay, 0, 0); 388 389 if ( ((savedStartSch.getTime() <= startSch.getTime()) && (savedEndSch.getTime() > startSch.getTime())) || 390 ((savedStartSch.getTime() < endSch.getTime()) && (savedEndSch.getTime() >= endSch.getTime())) || 391 ((savedStartSch.getTime() === startSch.getTime()) && (savedEndSch.getTime() === endSch.getTime())) || 392 ((startSch.getTime() === endSch.getTime()) && (savedEndSch.getTime() === startSch.getTime())) ) { 393 var result = {}; 394 checkErrorCodeNText(result, "TAHS", "Time.addHolidaySchedule returns failure. schedule is not valid"); 395 errorCallback(result); 396 return; 397 } 398 } 399 400 schedule.startMonth = options.startMonth; 401 schedule.startDay = options.startDay; 402 schedule.endMonth = options.endMonth; 403 schedule.endDay = options.endDay; 404 scheduleList.push(schedule); 405 406 log("scheduleList : " + JSON.stringify(scheduleList)); 407 408 service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", { 409 method: "set", 410 parameters: { 411 category: "commercial", 412 settings: { 413 "holidaySchedule": scheduleList 414 } 415 }, 416 onSuccess: function(result) { 417 log("addHolidaySchedule: On Success"); 418 419 if (result.returnValue === true) { 420 if (typeof successCallback === 'function') { 421 successCallback(); 422 } 423 } 424 }, 425 onFailure: function(result) { 426 log("addHolidaySchedule: On Failure"); 427 delete result.returnValue; 428 if (typeof errorCallback === 'function') { 429 checkErrorCodeNText(result, "TAHS", "Time.addHolidaySchedule returns failure."); 430 errorCallback(result); 431 } 432 } 433 }); 434 } 435 } 436 }, 437 onFailure : function(result) { 438 log("addHolidaySchedule: On Failure"); 439 delete result.returnValue; 440 if (typeof errorCallback === 'function') { 441 checkErrorCodeNText(result, "TAHS", "Time.addHolidaySchedule returns failure."); 442 errorCallback(result); 443 } 444 } 445 }); 446 447 log("Time.addHolidaySchedule Done"); 448 }; 449 450 /** 451 * del HolidaySchedule 452 * @class Time 453 * @param {Function} successCallback success callback function. 454 * @param {Function} errorCallback failure callback function. 455 * @param {Object} options 456 * <div align=left> 457 * <table class="hcap_spec" width=400> 458 * <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead> 459 * <tbody> 460 * <tr><th>schduleId</th><th>String</th><th>schedule id (getAllHolidaySchedules() ���� ���� schedule id)</th><th>required</th></tr> 461 * </tbody> 462 * </table> 463 * </div> 464 * @return <p>If the method is successfully executed, call the success callback function without a parameter.</br> 465 * If an error occurs, failure callback function is called with failure callback object as a parameter.</p> 466 * @example 467 * // Javascript code 468 * 469 * function delHolidaySchedule () { 470 * var options = { 471 * scheduleId : "d704" 472 * }; 473 * 474 * function successCb() { 475 * // Do something 476 * } 477 * 478 * function failureCb(cbObject) { 479 * var errorCode = cbObject.errorCode; 480 * var errorText = cbObject.errorText; 481 * console.log ("Error Code [" + errorCode + "]: " + errorText); 482 * } 483 * 484 * var time = new Time(); 485 * time.delHolidaySchedule(successCb, failureCb, options); 486 * } 487 * @since 1.4 488 * @see 489 * <a href="Time%23getHolidayScheduleMode.html">Time.getHolidayScheduleMode()</a><br> 490 */ 491 Time.prototype.delHolidaySchedule = function (successCallback, errorCallback, options) { 492 log("delHolidaySchedule: " + "id : " + options.scheduleId); 493 494 var ret = { }; 495 checkErrorCodeNText(ret, "ERROR", "This function is not supported on webOS 3.2"); 496 errorCallback(ret); 497 return; 498 499 if ((typeof options.scheduleId !== 'string' || options.scheduleId === undefined || options.scheduleId === null) && typeof errorCallback === 'function') 500 { 501 var result = {}; 502 checkErrorCodeNText(result, "TDHS", "Time.delHolidaySchedule returns failure. scheduleId is not valid."); 503 errorCallback(result); 504 log("Time.delHolidaySchedule invalid "); 505 return; 506 } 507 508 service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", { 509 method : "get", 510 parameters : { 511 category : "commercial", 512 keys : ["holidaySchedule"] 513 }, 514 onSuccess : function(result) { 515 log("getHolidaySchedule: On Success"); 516 517 if (result.returnValue === true) { 518 if (typeof successCallback === 'function') { 519 var scheduleList = null; 520 var tempList = []; 521 var flag = false; 522 523 scheduleList = result.settings.holidaySchedule; 524 525 log("before scheduleList : " + JSON.stringify(scheduleList)); 526 527 for(var i=0; i<scheduleList.length; i++) { 528 if(scheduleList[i]._id === options.scheduleId) { 529 flag = true; 530 } else { 531 tempList.push(scheduleList[i]); //copy schedulelist except for schedule to remove 532 } 533 } 534 535 if(flag === false && typeof errorCallback === 'function') { 536 var result = {}; 537 checkErrorCodeNText(result, "TDHS", "Time.delHolidaySchedule returns failure. can not find schedule id."); 538 errorCallback(result); 539 log("Time.delHolidaySchedule invalid "); 540 return; 541 } 542 543 log("after scheduleList : " + JSON.stringify(tempList)); 544 545 service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", { 546 method: "set", 547 parameters: { 548 category: "commercial", 549 settings: { 550 "holidaySchedule": tempList 551 } 552 }, 553 onSuccess: function(result) { 554 log("delHolidaySchedule: On Success"); 555 556 if (result.returnValue === true) { 557 if (typeof successCallback === 'function') { 558 successCallback(); 559 } 560 } 561 }, 562 onFailure: function(result) { 563 log("delHolidaySchedule: On Failure"); 564 delete result.returnValue; 565 if (typeof errorCallback === 'function') { 566 checkErrorCodeNText(result, "TDHS", "Time.delHolidaySchedule returns failure."); 567 errorCallback(result); 568 } 569 } 570 }); 571 } 572 } 573 }, 574 onFailure : function(result) { 575 log("delHolidaySchedule: On Failure"); 576 delete result.returnValue; 577 if (typeof errorCallback === 'function') { 578 checkErrorCodeNText(result, "TDHS", "Time.delHolidaySchedule returns failure."); 579 errorCallback(result); 580 } 581 } 582 }); 583 584 log("Time.delHolidaySchedule Done"); 585 }; 586 587 /** 588 * delAll HolidaySchedule 589 * @class Time 590 * @param {Function} successCallback success callback function. 591 * @param {Function} errorCallback failure callback function. 592 * @param {Object} None 593 * @return <p>If the method is successfully executed, call the success callback function without a parameter.</br> 594 * If an error occurs, failure callback function is called with failure callback object as a parameter.</p> 595 * @example 596 * // Javascript code 597 * 598 * function delAllHolidaySchedule () { 599 * function successCb() { 600 * // Do something 601 * } 602 * 603 * function failureCb(cbObject) { 604 * var errorCode = cbObject.errorCode; 605 * var errorText = cbObject.errorText; 606 * console.log ("Error Code [" + errorCode + "]: " + errorText); 607 * } 608 * 609 * var time = new Time(); 610 * time.delAllHolidaySchedule(successCb, failureCb); 611 * } 612 * @since 1.4 613 * @see 614 * <a href="Time%23getHolidayScheduleMode.html">Time.getHolidayScheduleMode()</a><br> 615 */ 616 Time.prototype.delAllHolidaySchedules = function (successCallback, errorCallback) { 617 log("delAllHolidaySchedules: "); 618 619 var ret = { }; 620 checkErrorCodeNText(ret, "ERROR", "This function is not supported on webOS 3.2"); 621 errorCallback(ret); 622 return; 623 624 service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", { 625 method: "set", 626 parameters: { 627 category: "commercial", 628 settings: { 629 "holidaySchedule": [] 630 } 631 }, 632 onSuccess: function(result) { 633 log("delAllHolidaySchedules: On Success"); 634 635 if (result.returnValue === true) { 636 if (typeof successCallback === 'function') { 637 successCallback(); 638 } 639 } 640 }, 641 onFailure: function(result) { 642 log("delAllHolidaySchedules: On Failure"); 643 delete result.returnValue; 644 if (typeof errorCallback === 'function') { 645 checkErrorCodeNText(result, "TDAS", "Time.delAllHolidaySchedules returns failure."); 646 errorCallback(result); 647 } 648 } 649 }); 650 651 log("Time.delAllHolidaySchedules Done"); 652 }; 653 654 /** 655 * Gets all HolidaySchedule List 656 * @class Time 657 * @param {Function} successCallback success callback function. 658 * @param {Function} errorCallback failure callback function. 659 * @return {Object} 660 * <div align=left> 661 * <table class="hcap_spec" width=400> 662 * <thead><tr><th>Property</th><th>Type</th><th>Description</th></tr></thead> 663 * <tbody> 664 * <tr><th>holidayScheduleList[]</th><th>Array</th><th>holiday schedule list</th></tr> 665 * <tr class="odd"><tr><th>holidayScheduleList[]._id</th><th>String</th><th>schedule id</th></tr> 666 * <tr><th>holidayScheduleList[].startMonth</th><th>Number</th><th>start month</th></tr> 667 * <tr class="odd"><tr><th>holidayScheduleList[].startDay</th><th>Number</th><th> start day</th></tr> 668 * <tr><th>holidayScheduleList[].endMonth</th><th>Number</th><th>end month</th></tr> 669 * <tr class="odd"><tr><th>holidayScheduleList[].endDay</th><th>Number</th><th>end day</th></tr> 670 * </tbody> 671 * </table> 672 * 673 * @example 674 * // Javascript code 675 * function getAllHolidaySchedules () { 676 * function successCb(cbObject) { 677 * console.log("cbObject : " + JSON.stringify(cbObject)); 678 * for (var i = cbObject.holidayScheduleList.length-1; i>=0; i--) { 679 * console.log("holidayScheduleList[" + i + "].startMonth : " + cbObject.holidayScheduleList[i].startMonth); 680 * console.log("holidayScheduleList[" + i + "].startDay : " + cbObject.holidayScheduleList[i].startDay); 681 * console.log("holidayScheduleList[" + i + "].endMonth : " + cbObject.holidayScheduleList[i].endMonth); 682 * console.log("holidayScheduleList[" + i + "].endDay : " + cbObject.holidayScheduleList[i].endDay); 683 * } 684 * } 685 * function failureCb(cbObject) { 686 * var errorCode = cbObject.errorCode; 687 * var errorText = cbObject.errorText; 688 * console.log ("Error Code [" + errorCode + "]: " + errorText); 689 * } 690 * var time = new Time(); 691 * time.getAllHolidaySchedules(successCb, failureCb); 692 * } 693 * @since 1.4 694 * @see 695 * <a href="Time%23getHolidayScheduleMode.html">Time.getHolidayScheduleMode()</a><br> 696 */ 697 Time.prototype.getAllHolidaySchedules = function (successCallback, errorCallback) { 698 log("getAllHolidaySchedules: "); 699 700 var ret = { }; 701 checkErrorCodeNText(ret, "ERROR", "This function is not supported on webOS 3.2"); 702 errorCallback(ret); 703 return; 704 705 service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", { 706 method : "get", 707 parameters : { 708 category : "commercial", 709 keys : ["holidaySchedule"] 710 }, 711 onSuccess : function(result) { 712 log("getHolidaySchedule: On Success"); 713 714 if (result.returnValue === true) { 715 if (typeof successCallback === 'function') { 716 var cbObj = {}; 717 cbObj.holidayScheduleList = result.settings.holidaySchedule; 718 719 if (typeof successCallback === 'function') { 720 successCallback(cbObj); 721 } 722 } 723 } 724 }, 725 onFailure : function(result) { 726 log("getAllHolidaySchedules: On Failure"); 727 delete result.returnValue; 728 if (typeof errorCallback === 'function') { 729 checkErrorCodeNText(result, "TGAS", "Time.getAllHolidaySchedules returns failure."); 730 errorCallback(result); 731 } 732 } 733 }); 734 735 log("Time.getAllHolidaySchedules Done"); 736 }; 737 738 /** 739 * Gets HolidaySchedule 740 * @class Time 741 * @param {Function} successCallback success callback function. 742 * @param {Function} errorCallback failure callback function. 743 * @return {Object} 744 * <div align=left> 745 * <table class="hcap_spec" width=400> 746 * <thead><tr><th>Property</th><th>Type</th><th>Description</th></tr></thead> 747 * <tbody> 748 * <tr><th>holidayScheduleList[]</th><th>Array</th><th>holiday schedule list</th></tr> 749 * <tr class="odd"><tr><th>holidayScheduleList[]._id</th><th>String</th><th>schedule id</th></tr> 750 * <tr><th>holidayScheduleList[].month</th><th>Number</th><th>month</th></tr> 751 * <tr class="odd"><tr><th>holidayScheduleList[].year</th><th>Number</th><th>year</th></tr> 752 * <tr><th>holidayScheduleList[].date</th><th>Number</th><th>date</th></tr> 753 * <tr class="odd"><tr><th>holidayScheduleList[].repeatBy</th><th>String</th><th>repeatBy</th></tr> 754 * <tr><th>holidayScheduleList[].days</th><th>Number</th><th>days</th></tr> 755 * <tr class="odd"><tr><th>holidayScheduleList[].repeat</th><th>String</th><th>repeat</th></tr> 756 * </tbody> 757 * </table> 758 * 759 * @example 760 * // Javascript code 761 * function getHolidaySchedules () { 762 * function successCb(cbObject) { 763 * console.log("cbObject : " + JSON.stringify(cbObject)); 764 * for (var i = cbObject.holidayScheduleList.length-1; i>=0; i--) { 765 * console.log("holidayScheduleList[" + i + "]._id : " + cbObject.holidayScheduleList[i]._id); 766 * console.log("holidayScheduleList[" + i + "].month : " + cbObject.holidayScheduleList[i].settings.month); 767 * console.log("holidayScheduleList[" + i + "].year : " + cbObject.holidayScheduleList[i].settings.year); 768 * console.log("holidayScheduleList[" + i + "].date : " + cbObject.holidayScheduleList[i].settings.date); 769 * console.log("holidayScheduleList[" + i + "].repeatBy : " + cbObject.holidayScheduleList[i].settings.repeatBy); 770 * console.log("holidayScheduleList[" + i + "].days : " + cbObject.holidayScheduleList[i].settings.days); 771 * console.log("holidayScheduleList[" + i + "].repeat : " + cbObject.holidayScheduleList[i].settings.repeat); 772 * } 773 * } 774 * function failureCb(cbObject) { 775 * var errorCode = cbObject.errorCode; 776 * var errorText = cbObject.errorText; 777 * console.log ("Error Code [" + errorCode + "]: " + errorText); 778 * } 779 * var time = new Time(); 780 * time.getHolidaySchedule(successCb, failureCb); 781 * } 782 * @since 1.5 783 * @see 784 * <a href="Time%23setHolidaySchedule.html">Time.setHolidaySchedule()</a><br> 785 * <a href="Time%23unsetHolidaySchedule.html">Time.unsetHolidaySchedule()</a><br> 786 */ 787 788 Time.prototype.getHolidaySchedule = function (successCallback, errorCallback) { 789 log("getHolidaySchedule: "); 790 service.Request("luna://com.webos.service.commercial.signage.storageservice/", { 791 method : "getHolidaySchedule", 792 parameters: {}, 793 onSuccess : function(result) { 794 log("getHolidaySchedule: On Success"); 795 796 if (result.returnValue === true) { 797 if (typeof successCallback === 'function') { 798 var cbObj = {}; 799 cbObj.holidayScheduleList = result.settings.holidaySchedule; 800 801 if (typeof successCallback === 'function') { 802 successCallback(cbObj); 803 } 804 } 805 } 806 }, 807 onFailure : function(result) { 808 log("getHolidaySchedule: On Failure"); 809 delete result.returnValue; 810 if (typeof errorCallback === 'function') { 811 checkErrorCodeNText(result, "TGAS", "Time.getHolidaySchedule returns failure."); 812 errorCallback(result); 813 } 814 } 815 }); 816 817 log("Time.getHolidaySchedule Done"); 818 }; 819 820 /** 821 * Sets HolidaySchedule 822 * @class Time 823 * @param {Function} successCallback success callback function. 824 * @param {Function} errorCallback failure callback function. 825 * @param {Object} options 826 * <div align=left> 827 * <table class="hcap_spec" width=400> 828 * <thead><tr><th>Property</th><th>Type</th><th>Description</th></tr></thead> 829 * <tbody> 830 * <tr><th>holidaySchedule[]</th><th>Array</th><th>holiday schedule list</th></tr> 831 * <tr class="odd"><tr><th>holidaySchedule[].name</th><th>String</th><th>schedule name</th></tr> 832 * <tr><th>holidaySchedule[].settings.year</th><th>Number</th><th>year</th></tr> 833 * <tr class="odd"><tr><th>holidaySchedule[].settings.year</th><th>Number</th><th>month</th></tr> 834 * <tr><th>holidaySchedule[].settings.date</th><th>Number</th><th>date</th></tr> 835 * <tr class="odd"><tr><th>holidaySchedule[].settings.days</th><th>Number</th><th>day</th></tr> 836 * <tr><th>holidaySchedule[].settings.repeat</th><th>String</th><th>repeat</th></tr> 837 * <tr class="odd"><tr><th>holidaySchedule[].settings.repeatBy</th><th>String</th><th>repeatBy</th></tr> 838 * </tbody> 839 * </table> 840 * 841 * @example 842 * // Javascript code 843 * function setAllHolidaySchedules () { 844 * var params = { 845 * "holidaySchedule":[ 846 * { 847 * "settings":{ 848 * "year":2016, 849 * "month":12, 850 * "date":31, 851 * "days":1, 852 * "repeat":"none", 853 * "repeatBy":"none" 854 * }, 855 * "name":"Holiday Name 01" 856 * } 857 * ] 858 * } 859 * function successCb(cbObject) { 860 * console.log("sucess"); 861 * // Do something 862 * } 863 * function failureCb(cbObject) { 864 * var errorCode = cbObject.errorCode; 865 * var errorText = cbObject.errorText; 866 * console.log ("Error Code [" + errorCode + "]: " + errorText); 867 * } 868 * var time = new Time(); 869 * time.setHolidaySchedule(successCb, failureCb, params); 870 * } 871 * @since 1.4 872 * @see 873 * <a href="Time%23getHolidaySchedule.html">Time.getHolidaySchedule()</a><br> 874 * <a href="Time%23unsetHolidaySchedule.html">Time.unsetHolidaySchedule()</a><br> 875 */ 876 877 Time.prototype.setHolidaySchedule = function (successCallback, errorCallback, params) { 878 log("setHolidaySchedule: "); 879 service.Request("luna://com.webos.service.commercial.signage.storageservice/", { 880 method : "setHolidaySchedule", 881 parameters : params, 882 onSuccess : function(result) { 883 log("setHolidaySchedule: On Success"); 884 885 if (result.returnValue === true) { 886 if (typeof successCallback === 'function') { 887 if (typeof successCallback === 'function') { 888 successCallback(); 889 } 890 } 891 } 892 }, 893 onFailure : function(result) { 894 log("setHolidaySchedule: On Failure"); 895 delete result.returnValue; 896 if (typeof errorCallback === 'function') { 897 checkErrorCodeNText(result, "TGAS", "Time.setHolidaySchedule returns failure."); 898 errorCallback(result); 899 } 900 } 901 }); 902 903 log("Time.setHolidaySchedule Done"); 904 }; 905 906 /** 907 * Unset HolidaySchedule List 908 * @class Time 909 * @param {Function} successCallback success callback function. 910 * @param {Function} errorCallback failure callback function. 911 * @return {Object} 912 * <div align=left> 913 * 914 * @example 915 * // Javascript code 916 * function unsetHolidaySchedule () { 917 * function successCb(cbObject) { 918 * console.log("sucess"); 919 * // Do something 920 * } 921 * function failureCb(cbObject) { 922 * var errorCode = cbObject.errorCode; 923 * var errorText = cbObject.errorText; 924 * console.log ("Error Code [" + errorCode + "]: " + errorText); 925 * } 926 * var time = new Time(); 927 * time.unsetHolidaySchedule(successCb, failureCb); 928 * } 929 * @since 1.5 930 * @see 931 * <a href="Time%23setHolidaySchedule.html">Time.setHolidaySchedule()</a><br> 932 * <a href="Time%23getHolidaySchedule.html">Time.getHolidaySchedule()</a><br> 933 */ 934 935 Time.prototype.unsetHolidaySchedule = function (successCallback, errorCallback) { 936 log("unsetHolidaySchedule: "); 937 service.Request("luna://com.webos.service.commercial.signage.storageservice/", { 938 method : "unsetHolidaySchedule", 939 parameters : {}, 940 onSuccess : function(result) { 941 log("unsetHolidaySchedule: On Success"); 942 943 if (result.returnValue === true) { 944 if (typeof successCallback === 'function') { 945 if (typeof successCallback === 'function') { 946 successCallback(); 947 } 948 } 949 } 950 }, 951 onFailure : function(result) { 952 log("unsetHolidaySchedule: On Failure"); 953 delete result.returnValue; 954 if (typeof errorCallback === 'function') { 955 checkErrorCodeNText(result, "TGAS", "Time.unsetHolidaySchedule returns failure."); 956 errorCallback(result); 957 } 958 } 959 }); 960 961 log("Time.unsetHolidaySchedule Done"); 962 }; 963 964 module.exports = Time; 965 }); 966 967 Time = cordova.require('cordova/plugin/time'); // jshint ignore:line 968 969