1 /** 2 * @fileoverview The preference server script controls all the preference server communication. 3 */ 4 5 6 7 /** 8 * @ignore 9 */ 10 var Ozone = Ozone || {}; 11 12 /** 13 * @ignore 14 */ 15 Ozone.pref = Ozone.pref || {}; 16 17 (function(window, document, undefined) { 18 /** 19 * @constructor None, this is a Singleton 20 * @description This object is used to create, retrieve, update and delete user preferences. A user preference is simply a string 21 * stored in OWF that is uniquely mapped to a user, namespace, and name combination. 22 * <br><br> 23 * All public methods of this class accept an onSuccess function. This function is executed upon successful completion of the requested operation and is passed a copy of the preference object. 24 * @example 25 * The following is an example of a preference object passed to the onSuccess 26 * function: 27 * 28 * { 29 * "value":"true", 30 * "path":"militaryTime", 31 * "user": 32 * { 33 * "userId":"testAdmin1" 34 * }, 35 * "namespace":"com.mycompany.AnnouncingClock" 36 * } 37 * 38 * Where: 39 * 40 * value: The preference value that is stored in the database. This can be any string 41 * including JSON. 42 * path: The name of the user preference. 43 * user: The user object. The only user information returned at this time is the user 44 * ID. 45 * namespace: The namespace of the requested user preference. 46 * 47 * @requires Ozone.util.Transport 48 */ 49 Ozone.pref.PrefServer = function(_url) { 50 if ( _url === undefined || _url === "null" || _url.indexOf('$') !== -1 || _url.length === 0 ) { 51 // default incase no prefLocation is given 52 // ugly alert message, but let's fail fast 53 // alert("prefsLocation is null or incorrect. Perhaps in the OwfConfig.xml file?"); 54 } else { 55 //Strip off a trailing slash. 56 if (_url.lastIndexOf("/") === (_url.length -1)) { 57 _url = _url.substring(0,_url.length-1); 58 } 59 } 60 61 /** @private 62 * @description Look up a value for the given url. This should generally not be called from user code, rather, an entity-specific method should be called. 63 * @return JSON object representing the requested preference 64 * @param cfg config object see below for properties 65 * @param cfg.url url to be used in the call 66 * @param cfg.onSuccess callback function to capture the success result 67 * @param cfg.onFailure callback to execute if there is an error (optional, a default alert is provided) 68 * @param cfg.ignoredErrorCodes allows the caller to ignore certain http error codes. If they occur onsuccess will be called with a null payload 69 * 70 * @example var prefs = new Ozone.pref.Prefs(); 71 * 72 * var mysuccess = function(result){ 73 * this.value = result; 74 * alert(result); 75 * alert(result.value); 76 * 77 * getValue({url:_url + "/" + namespace + "/" + path, onSuccess:onSuccessCallback, onFailure:onFailCallback}); 78 * 79 */ 80 var get = function (cfg) { 81 cfg.method = "GET"; 82 cfg.async = true; 83 Ozone.util.Transport.send(cfg); 84 }; 85 86 /** @private 87 * @description Delete instance of the given url. This should generally not be called from user code, rather, an entity-specific method should be called. 88 * @param cfg config object see below for properties 89 * @param cfg.url url to be used in the call 90 * @param cfg.onSuccess callback function to capture the success result 91 * @param cfg.onFailure callback to execute if there is an error (optional, a default alert is provided) 92 * 93 * @example 94 * var onSuccess = function(result){ 95 * this.value = result; 96 * alert(result); 97 * } 98 * 99 * var onFailure = function(err) { 100 * alert("There was an error: " + err); 101 * } 102 * 103 * deleteBase({url:_url + "/" + namespace + "/" + path, onSuccess:onSuccessCallback, onFailure:onFailCallback}); 104 */ 105 var deleteBase = function (cfg) { 106 cfg.method = 'DELETE'; 107 setValue(cfg); 108 }; 109 110 /** @private 111 * @description Get an array of object for the requested namespace 112 * @param cfg config object see below for properties 113 * @param cfg.url - string 114 * @param cfg.onSuccess - callback function to capture the success result 115 * @param cfg.onFailure - callback to execute if there is an error (optional, a default alert provided) 116 * @example 117 * var onSuccess = function(result){ 118 * this.value = result; 119 * alert(result); 120 * } 121 * 122 * var onFailure = function(err) { 123 * alert("There was an error: " + err); 124 * } 125 * 126 * list({namespace:"namespace1", onSuccess:onSuccess, onFailure:onFailure}); 127 */ 128 var list = function (cfg) { 129 cfg.url = _url + "/" + cfg.url; 130 get(cfg); 131 }; 132 133 /** 134 * @private 135 * @description Set a value for the given url. This should generally not be called from user code, rather, an entity-specific method should be called. 136 * @param cfg.url url to be used in the call 137 * @param cfg.content The content of the send. Either map or JSON with the _method property already defined. 138 * @param cfg.onSuccess callback function to capture the success result (optional) 139 * @param cfg.onFailure callback to execute if there is an error (optional, a default alert is provided if an onSuccess callback is passed in) 140 * @example 141 * var onSuccess = function(result){ 142 * this.value = result; 143 * alert(result); //TODO: the preference server currently doesn't return anything 144 * } 145 * 146 * var onFailure = function(err) { 147 * alert("There was an error: " + err); 148 * } 149 * 150 * setValueBase(_url + "/" + namespace + "/" + path, content, onSuccessCallback, onFailCallback); 151 */ 152 var setValueBase = function(cfg) 153 { 154 cfg.method = cfg.content["_method"]; 155 if (cfg.onSuccess) { 156 if (!cfg.onFailure) { //must ensure there is an onfailure method, as we using content 157 cfg.onFailure = function(err) { 158 alert(Ozone.util.ErrorMessageString.saveUserPreferences + " : " + err); 159 }; 160 } 161 Ozone.util.Transport.send(cfg); 162 } else { 163 Ozone.util.Transport.sendAndForget(cfg); 164 } 165 166 }; 167 168 /** 169 * @private 170 * @description Set a value for the given url. This should generally not be called from user code, rather, an entity-specific method should be called. 171 * @param cfg config object see below for properties 172 * @param cfg.url url to be used in the call 173 * @param cfg.json The value to store. 174 * @param cfg.method The method for the call. ('DELETE', 'PUT') 175 * @param cfg.onSuccess callback function to capture the success result (optional) 176 * @param cfg.onFailure callback to execute if there is an error (optional, a default alert is provided if an onSuccess callback is passed in) 177 * @example 178 * var onSuccess = function(result){ 179 * this.value = result; 180 * alert(result); //TODO: the preference server currently doesn't return anything 181 * } 182 * 183 * var onFailure = function(err) { 184 * alert("There was an error: " + err); 185 * } 186 * 187 * setValue({url:_url + "/" + namespace + "/" + path, json:value, method:method, onSuccess:onSuccessCallback, onFailure:onFailCallback}); 188 */ 189 var setValue = function (cfg) { 190 if (cfg.method == null) { 191 cfg.method = 'PUT'; 192 } 193 194 var content = { 195 '_method': cfg.method 196 }; 197 198 if (cfg.json) { 199 content = { 200 '_method': cfg.method, 201 'name': cfg.json.name, 202 'layout': cfg.json.layout, 203 'description': cfg.json.description, 204 'columnCount': cfg.json.columnCount, 205 'guid': cfg.json.guid, 206 'isdefault': cfg.json.isdefault, 207 'locked': cfg.json.locked, 208 'state': cfg.json.state, 209 'defaultSettings': cfg.json.defaultSettings, 210 'showLaunchMenu': cfg.json.showLaunchMenu, 211 'layoutConfig': cfg.json.layoutConfig, 212 'intentConfig': cfg.json.intentConfig 213 }; 214 if (cfg.json.cloned === true) content.cloned = true; 215 if (cfg.json.bypassLayoutRearrange === true) content.bypassLayoutRearrange = true; 216 } 217 cfg.content = content; 218 setValueBase(cfg); 219 }; 220 221 /** 222 * @private 223 * @description Set a value for the given url by using a JSON object, allowing multiple parameters for PUT/POST. This should generally not be called from user code, rather, an entity-specific method should be called. 224 * @param cfg config object see below for properties 225 * @param cfg.url url to be used in the call 226 * @param cfg.jsonObject The parameters to pass in. Note that the value parameter is required, and this is what will be stored in the "value" column of the appropriate table. 227 * @param cfg.method The method for the call. ('DELETE', 'PUT') 228 * @param cfg.onSuccess callback function to capture the success result (optional) 229 * @param cfg.onFailure callback to execute if there is an error (optional, a default alert is provided if an onSuccess callback is passed in) 230 * @example 231 * 232 * ...code setting up a desktop dashboard 233 * 234 * var postParams = 235 * { 236 * 'value': this.config.value, 237 * 'path': this.config.value.guid, 238 * 'type': 'desktop', 239 * 'isdefault': saveAsDefault 240 * }; 241 * 242 * setValuesViaJSONObject(_url + "/" + namespace + "/" + path, jsonObject, saveMethod, onSuccess, onFailure); 243 */ 244 var setValuesViaJSONObject = function(cfg) { 245 if (cfg.jsonObject._method === undefined) 246 { 247 if (cfg.method == null) { 248 cfg.method = 'PUT'; 249 } 250 cfg.jsonObject._method = cfg.method; 251 } 252 cfg.json = cfg.jsonObject; 253 setValue(cfg); 254 255 }; 256 257 /** 258 * @private 259 * @description Create JSON object with params. This should generally not be called from user code. 260 * @param cfg config object see below for properties 261 * @param cfg.dashboardId 262 * @param cfg.value 263 * @param cfg.type 264 * @param cfg.isDefault 265 * @return the JSON object 266 */ 267 var generateDashboardPostParamsJSON = function (json) { 268 var postParams = { 269 'name': json.name, 270 'layout': json.layout, 271 'description': json.description, 272 'columnCount': json.columnCount, 273 'guid': json.guid, 274 'isdefault': json.isdefault, 275 'locked': json.locked, 276 'state': json.state, 277 'defaultSettings': json.defaultSettings, 278 'showLaunchMenu': json.showLaunchMenu, 279 'layoutConfig': typeof json.layoutConfig === 'string' ? json.layoutConfig : Ozone.util.toString(json.layoutConfig), 280 'intentConfig': typeof json.intentConfig === 'string' ? json.intentConfig : Ozone.util.toString(json.intentConfig) 281 }; 282 return postParams; 283 }; 284 285 return /** @lends Ozone.pref.PrefServer.prototype */{ 286 287 dashTypeDesktop: 'desktop', 288 289 dashTypeAccordion: 'accordion', 290 291 dashTypeTabbed: 'tabbed', 292 293 dashTypePortal: 'portal', 294 295 version: Ozone.version.owfversion + Ozone.version.preference, 296 297 /** 298 * @description Get the url for the Preference Server 299 * @returns {String} url 300 */ 301 getUrl : function() { 302 return _url; 303 }, 304 305 /** 306 * @description Sets the url for the Preference Server 307 * @param {String} url 308 * @returns void 309 */ 310 setUrl : function(url) { 311 _url = url; 312 }, 313 314 /** 315 * @description Gets the dashboard with the specified id 316 * @param {Object} cfg config object see below for properties 317 * @param {String} cfg.dashboardId Unigue dashbard identifier 318 * @param {Function} cfg.onSuccess Callback function to capture the success result. Callback parameter is json representation of a dashboard. 319 * This method will be passed the dashboard object which has the following properties:<br> 320 * <br> 321 * {Boolean} alteredByAdmin: true if altered by an administrator<br> 322 * {Date} createdDate: date dashboard was created<br> 323 * {Boolean} isGroupDashboard: true if dashboard is a group dashboard<br> 324 * {String} layout: layout of dashboard<br> 325 * {Boolean} isdefault: true if this is a default dashboard<br> 326 * {String} name: name of dashboard<br> 327 * {Number} columnCount: number of columns if dashboard is a portal type<br> 328 * {Object} user: the dashoard owner. Has the following properties:<br> 329 * {String} userId: unique user identifier<br> 330 * {List} EDashboardLayoutList: list of dashboard types<br> 331 * {String} defaultSettings: JSON string of default settings which varies by dashboard type<br> 332 * {Object} createdBy: dashboard creator. Has the following properties:<br> 333 * {String} userId: unique user identifier<br> 334 * {String} userRealName: user's name<br> 335 * {Date} editedDate: date dashboard was last edited<br> 336 * {Array} groups: groups dashboard is assigned to<br> 337 * {String} description: description of dashboard<br> 338 * {String} guid: uniqued dashboard identifier<br> 339 * {Array} state: array of widget state objects. Has the following properties:<br> 340 * {String} widgetGuid: unique widget identifier<br> 341 * {Number} width: width of widget in pixels<br> 342 * {Number} zIndex: in pixels<br> 343 * {String} region: containing region on dashboard. Dashboard type specific.<br> 344 * {Boolean} pinned: true if widget is pinned open<br> 345 * {String} buttonId: identifier of button that opens widget<br> 346 * {Number} height: height of widget in pixels<br> 347 * {Number} columnPos: position of widget in a column<br> 348 * {String} name: widget name<br> 349 * {Number} statePosition<br> 350 * {Boolean} active: true if this widget is the active (has focus) widget<br> 351 * {String} uniqueId: unique widget identifier on dashboard<br> 352 * {Boolean} minimized: true if widget is minimized<br> 353 * {Boolean} buttonOpened: true if button launched widget is opened<br> 354 * {Boolean} collapsed: true if widget is collapsed<br> 355 * {Number} y: y-axis position in pixels<br> 356 * {Number} x: x-axis position in pixels<br> 357 * {Boolean} maximized: true if widget is maximized<br> 358 * {Boolean} showLaunchMenu: true if launch menu is opened on dashboard<br> 359 * <br> 360 * @param {Function} [cfg.onFailure] Callback to execute if there is an error (optional, a default alert provided). Callback parameter is an error string. 361 * @example 362 * 363 * var onSuccess = function(dashboard) { 364 * alert(dashboard.name); 365 * }; 366 * 367 * var onFailure = function(error) { 368 * alert(error); 369 * }; 370 * 371 * Ozone.pref.PrefServer.getDashboard({ 372 * dashboardId:'917b4cd0-ecbd-410b-afd9-42d150c26426', 373 * onSuccess:onSuccess, 374 * onFailure:onFailure 375 * }); 376 */ 377 getDashboard : function (cfg){ 378 cfg.url = _url + "/" + 'dashboard' + "/" + cfg.dashboardId; 379 get(cfg); 380 }, 381 382 /** 383 * @description Gets the user's default dashboard 384 * @param {Object} cfg config object see below for properties 385 * @param {Function} cfg.onSuccess Callback function to capture the success result. Callback parameter is json representation of a Dashboard. 386 * This method will be passed the dashboard object which has the following properties:<br> 387 * <br> 388 * {Boolean} alteredByAdmin: true if altered by an administrator<br> 389 * {Date} createdDate: date dashboard was created<br> 390 * {Boolean} isGroupDashboard: true if dashboard is a group dashboard<br> 391 * {String} layout: layout of dashboard<br> 392 * {Boolean} isdefault: true if this is a default dashboard<br> 393 * {String} name: name of dashboard<br> 394 * {Number} columnCount: number of columns if dashboard is a portal type<br> 395 * {Object} user: the dashoard owner. Has the following properties:<br> 396 * {String} userId: unique user identifier<br> 397 * {List} EDashboardLayoutList: list of dashboard types<br> 398 * {String} defaultSettings: JSON string of default settings which varies by dashboard type<br> 399 * {Object} createdBy: dashboard creator. Has the following properties:<br> 400 * {String} userId: unique user identifier<br> 401 * {String} userRealName: user's name<br> 402 * {Date} editedDate: date dashboard was last edited<br> 403 * {Array} groups: groups dashboard is assigned to<br> 404 * {String} description: description of dashboard<br> 405 * {String} guid: uniqued dashboard identifier<br> 406 * {Array} state: array of widget state objects. Has the following properties:<br> 407 * {String} widgetGuid: unique widget identifier<br> 408 * {Number} width: width of widget in pixels<br> 409 * {Number} zIndex: in pixels<br> 410 * {String} region: containing region on dashboard. Dashboard type specific.<br> 411 * {Boolean} pinned: true if widget is pinned open<br> 412 * {String} buttonId: identifier of button that opens widget<br> 413 * {Number} height: height of widget in pixels<br> 414 * {Number} columnPos: position of widget in a column<br> 415 * {String} name: widget name<br> 416 * {Number} statePosition<br> 417 * {Boolean} active: true if this widget is the active (has focus) widget<br> 418 * {String} uniqueId: unique widget identifier on dashboard<br> 419 * {Boolean} minimized: true if widget is minimized<br> 420 * {Boolean} buttonOpened: true if button launched widget is opened<br> 421 * {Boolean} collapsed: true if widget is collapsed<br> 422 * {Number} y: y-axis position in pixels<br> 423 * {Number} x: x-axis position in pixels<br> 424 * {Boolean} maximized: true if widget is maximized<br> 425 * {Boolean} showLaunchMenu: true if launch menu is opened on dashboard<br> 426 * <br> 427 * @param {Function} [cfg.onFailure] Callback to execute if there is an error (optional, a default alert provided). Callback parameter is an error string. 428 * @example 429 * 430 * var onSuccess = function(dashboard) { 431 * alert(dashboard.name); 432 * }; 433 * 434 * var onFailure = function(error) { 435 * alert(error); 436 * }; 437 * 438 * Ozone.pref.PrefServer.getDefaultDashboard({ 439 * onSuccess:onSuccess, 440 * onFailure:onFailure 441 * }); 442 */ 443 getDefaultDashboard : function (cfg){ 444 cfg.url = _url +"/dashboard?isdefault=true"; 445 cfg.method = "POST"; 446 Ozone.util.Transport.send(cfg); 447 }, 448 449 /** 450 * @description Sets the user's default dashboard 451 * @param {Object} cfg config object see below for properties 452 * @param {String} cfg.dashboardId Unigue dashbard identifier 453 * @param {Boolean} cfg.isDefault true to set as default dashboard 454 * @param {Function} cfg.onSuccess Callback function to capture the success result. Callback parameter is json representation of a Dashboard. 455 * This method will be passed the dashboard object which has the following properties:<br> 456 * <br> 457 * {Boolean} alteredByAdmin: true if altered by an administrator<br> 458 * {Date} createdDate: date dashboard was created<br> 459 * {Boolean} isGroupDashboard: true if dashboard is a group dashboard<br> 460 * {String} layout: layout of dashboard<br> 461 * {Boolean} isdefault: true if this is a default dashboard<br> 462 * {String} name: name of dashboard<br> 463 * {Number} columnCount: number of columns if dashboard is a portal type<br> 464 * {Object} user: the dashoard owner. Has the following properties:<br> 465 * {String} userId: unique user identifier<br> 466 * {List} EDashboardLayoutList: list of dashboard types<br> 467 * {String} defaultSettings: JSON string of default settings which varies by dashboard type<br> 468 * {Object} createdBy: dashboard creator. Has the following properties:<br> 469 * {String} userId: unique user identifier<br> 470 * {String} userRealName: user's name<br> 471 * {Date} editedDate: date dashboard was last edited<br> 472 * {Array} groups: groups dashboard is assigned to<br> 473 * {String} description: description of dashboard<br> 474 * {String} guid: uniqued dashboard identifier<br> 475 * {Array} state: array of widget state objects. Has the following properties:<br> 476 * {String} widgetGuid: unique widget identifier<br> 477 * {Number} width: width of widget in pixels<br> 478 * {Number} zIndex: in pixels<br> 479 * {String} region: containing region on dashboard. Dashboard type specific.<br> 480 * {Boolean} pinned: true if widget is pinned open<br> 481 * {String} buttonId: identifier of button that opens widget<br> 482 * {Number} height: height of widget in pixels<br> 483 * {Number} columnPos: position of widget in a column<br> 484 * {String} name: widget name<br> 485 * {Number} statePosition<br> 486 * {Boolean} active: true if this widget is the active (has focus) widget<br> 487 * {String} uniqueId: unique widget identifier on dashboard<br> 488 * {Boolean} minimized: true if widget is minimized<br> 489 * {Boolean} buttonOpened: true if button launched widget is opened<br> 490 * {Boolean} collapsed: true if widget is collapsed<br> 491 * {Number} y: y-axis position in pixels<br> 492 * {Number} x: x-axis position in pixels<br> 493 * {Boolean} maximized: true if widget is maximized<br> 494 * {Boolean} showLaunchMenu: true if launch menu is opened on dashboard<br> 495 * <br> 496 * @param {Function} [cfg.onFailure] Callback to execute if there is an error (optional, a default alert provided). Callback parameter is an error string. 497 * @example 498 * 499 * var onSuccess = function(dashboard) { 500 * alert(dashboard.name); 501 * }; 502 * 503 * var onFailure = function(error) { 504 * alert(error); 505 * }; 506 * 507 * Ozone.pref.PrefServer.setDefaultDashboard({ 508 * dashboardId:'917b4cd0-ecbd-410b-afd9-42d150c26426', 509 * isDefault:true, 510 * onSuccess:onSuccess, 511 * onFailure:onFailure 512 * }); 513 */ 514 setDefaultDashboard : function (cfg){ 515 cfg.url = _url + "/dashboard/" + cfg.dashboardId + "?isdefault=" + cfg.isDefault; 516 cfg.method = 'PUT'; 517 setValue(cfg); 518 }, 519 520 /** 521 * @description Saves changes to a new or existing dashboard 522 * @param {Object} cfg config object see below for properties 523 * @param {Object} cfg.json The encoded JSON object representing the dashboard. 524 * The dashboard object has the following properties:<br> 525 * <br> 526 * {Boolean} alteredByAdmin: true if altered by an administrator<br> 527 * {Date} createdDate: date dashboard was created<br> 528 * {Boolean} isGroupDashboard: true if dashboard is a group dashboard<br> 529 * {String} layout: layout of dashboard<br> 530 * {Boolean} isdefault: true if this is a default dashboard<br> 531 * {String} name: name of dashboard<br> 532 * {Number} columnCount: number of columns if dashboard is a portal type<br> 533 * {Object} user: the dashoard owner. Has the following properties:<br> 534 * {String} userId: unique user identifier<br> 535 * {List} EDashboardLayoutList: list of dashboard types<br> 536 * {String} defaultSettings: JSON string of default settings which varies by dashboard type<br> 537 * {Object} createdBy: dashboard creator. Has the following properties:<br> 538 * {String} userId: unique user identifier<br> 539 * {String} userRealName: user's name<br> 540 * {Date} editedDate: date dashboard was last edited<br> 541 * {Array} groups: groups dashboard is assigned to<br> 542 * {String} description: description of dashboard<br> 543 * {String} guid: uniqued dashboard identifier<br> 544 * {Array} state: array of widget state objects. Has the following properties:<br> 545 * {String} widgetGuid: unique widget identifier<br> 546 * {Number} width: width of widget in pixels<br> 547 * {Number} zIndex: in pixels<br> 548 * {String} region: containing region on dashboard. Dashboard type specific.<br> 549 * {Boolean} pinned: true if widget is pinned open<br> 550 * {String} buttonId: identifier of button that opens widget<br> 551 * {Number} height: height of widget in pixels<br> 552 * {Number} columnPos: position of widget in a column<br> 553 * {String} name: widget name<br> 554 * {Number} statePosition<br> 555 * {Boolean} active: true if this widget is the active (has focus) widget<br> 556 * {String} uniqueId: unique widget identifier on dashboard<br> 557 * {Boolean} minimized: true if widget is minimized<br> 558 * {Boolean} buttonOpened: true if button launched widget is opened<br> 559 * {Boolean} collapsed: true if widget is collapsed<br> 560 * {Number} y: y-axis position in pixels<br> 561 * {Number} x: x-axis position in pixels<br> 562 * {Boolean} maximized: true if widget is maximized<br> 563 * {Boolean} showLaunchMenu: true if launch menu is opened on dashboard<br> 564 * <br> 565 * @param {Boolean} cfg.saveAsNew A Boolean indicating whether the entity being saved is new. 566 * @param {Function} cfg.onSuccess Callback function to capture the success result. Callback parameter is json representation of a Dashboard. 567 * This method will be passed the dashboard object which has the following properties:<br> 568 * <br> 569 * {Boolean} alteredByAdmin: true if altered by an administrator<br> 570 * {Date} createdDate: date dashboard was created<br> 571 * {Boolean} isGroupDashboard: true if dashboard is a group dashboard<br> 572 * {String} layout: layout of dashboard<br> 573 * {Boolean} isdefault: true if this is a default dashboard<br> 574 * {String} name: name of dashboard<br> 575 * {Number} columnCount: number of columns if dashboard is a portal type<br> 576 * {Object} user: the dashoard owner. Has the following properties:<br> 577 * {String} userId: unique user identifier<br> 578 * {List} EDashboardLayoutList: list of dashboard types<br> 579 * {String} defaultSettings: JSON string of default settings which varies by dashboard type<br> 580 * {Object} createdBy: dashboard creator. Has the following properties:<br> 581 * {String} userId: unique user identifier<br> 582 * {String} userRealName: user's name<br> 583 * {Date} editedDate: date dashboard was last edited<br> 584 * {Array} groups: groups dashboard is assigned to<br> 585 * {String} description: description of dashboard<br> 586 * {String} guid: uniqued dashboard identifier<br> 587 * {Array} state: array of widget state objects. Has the following properties:<br> 588 * {String} widgetGuid: unique widget identifier<br> 589 * {Number} width: width of widget in pixels<br> 590 * {Number} zIndex: in pixels<br> 591 * {String} region: containing region on dashboard. Dashboard type specific.<br> 592 * {Boolean} pinned: true if widget is pinned open<br> 593 * {String} buttonId: identifier of button that opens widget<br> 594 * {Number} height: height of widget in pixels<br> 595 * {Number} columnPos: position of widget in a column<br> 596 * {String} name: widget name<br> 597 * {Number} statePosition<br> 598 * {Boolean} active: true if this widget is the active (has focus) widget<br> 599 * {String} uniqueId: unique widget identifier on dashboard<br> 600 * {Boolean} minimized: true if widget is minimized<br> 601 * {Boolean} buttonOpened: true if button launched widget is opened<br> 602 * {Boolean} collapsed: true if widget is collapsed<br> 603 * {Number} y: y-axis position in pixels<br> 604 * {Number} x: x-axis position in pixels<br> 605 * {Boolean} maximized: true if widget is maximized<br> 606 * {Boolean} showLaunchMenu: true if launch menu is opened on dashboard<br> 607 * <br> 608 * @param {Function} [cfg.onFailure] Callback to execute if there is an error (optional, a default alert provided). Callback parameter is an error string. 609 * @param {Boolean} [cfg.async] Async true or false defaults to true 610 * @example 611 * 612 * var onSuccess = function(dashboard) { 613 * alert(dashboard.name); 614 * }; 615 * 616 * var onFailure = function(error) { 617 * alert(error); 618 * }; 619 * 620 * var dashboard = { 621 * alteredByAdmin: 'false', 622 * createdDate: '04/18/2012 11:29 AM EDT', 623 * isGroupDashboard: false, 624 * layout: 'desktop', 625 * isdefault: false, 626 * name: 'My Dashboard', 627 * columnCount: 0, 628 * user: { 629 * userId: 'testAdmin1', 630 * }, 631 * EDashboardLayoutList: ['accordion', 'desktop', 'portal', 'tabbed'], 632 * defaultSettings: {}, 633 * createdBy: { 634 * userId: 'testAdmin1', 635 * userRealName: 'Test Admin 1' 636 * }, 637 * editedDate: '04/18/2012 11:29 AM EDT', 638 * groups: [], 639 * description: 'This is my dashboard', 640 * guid: guid.util.guid(), 641 * state: [], 642 * showLaunchMenu: false 643 * }; 644 * 645 * Ozone.pref.PrefServer.createOrUpdateDashboard({ 646 * json: dashboard, 647 * saveAsNew: true, 648 * onSuccess: onSuccess, 649 * onFailure: onFailure, 650 * async: true 651 * }); 652 */ 653 createOrUpdateDashboard : function (cfg){ 654 cfg.url = _url + "/" + 'dashboard' + "/" + cfg.json.guid; 655 var postParams = generateDashboardPostParamsJSON(cfg.json); 656 postParams.bypassLayoutRearrange = true; 657 cfg.method = cfg.saveAsNew ? 'POST' : 'PUT'; 658 cfg.jsonObject = postParams; 659 setValuesViaJSONObject(cfg); 660 }, 661 662 /** 663 * @description Copies an existing dashboard and saves it as new 664 * @param {Object} cfg config object see below for properties 665 * @param {Object} cfg.json The encoded JSON object representing the dashboard. 666 * The dashboard object has the following properties:<br> 667 * <br> 668 * {Boolean} alteredByAdmin: true if altered by an administrator<br> 669 * {Date} createdDate: date dashboard was created<br> 670 * {Boolean} isGroupDashboard: true if dashboard is a group dashboard<br> 671 * {String} layout: layout of dashboard<br> 672 * {Boolean} isdefault: true if this is a default dashboard<br> 673 * {String} name: name of dashboard<br> 674 * {Number} columnCount: number of columns if dashboard is a portal type<br> 675 * {Object} user: the dashoard owner. Has the following properties:<br> 676 * {String} userId: unique user identifier<br> 677 * {List} EDashboardLayoutList: list of dashboard types<br> 678 * {String} defaultSettings: JSON string of default settings which varies by dashboard type<br> 679 * {Object} createdBy: dashboard creator. Has the following properties:<br> 680 * {String} userId: unique user identifier<br> 681 * {String} userRealName: user's name<br> 682 * {Date} editedDate: date dashboard was last edited<br> 683 * {Array} groups: groups dashboard is assigned to<br> 684 * {String} description: description of dashboard<br> 685 * {String} guid: uniqued dashboard identifier<br> 686 * {Array} state: array of widget state objects. Has the following properties:<br> 687 * {String} widgetGuid: unique widget identifier<br> 688 * {Number} width: width of widget in pixels<br> 689 * {Number} zIndex: in pixels<br> 690 * {String} region: containing region on dashboard. Dashboard type specific.<br> 691 * {Boolean} pinned: true if widget is pinned open<br> 692 * {String} buttonId: identifier of button that opens widget<br> 693 * {Number} height: height of widget in pixels<br> 694 * {Number} columnPos: position of widget in a column<br> 695 * {String} name: widget name<br> 696 * {Number} statePosition<br> 697 * {Boolean} active: true if this widget is the active (has focus) widget<br> 698 * {String} uniqueId: unique widget identifier on dashboard<br> 699 * {Boolean} minimized: true if widget is minimized<br> 700 * {Boolean} buttonOpened: true if button launched widget is opened<br> 701 * {Boolean} collapsed: true if widget is collapsed<br> 702 * {Number} y: y-axis position in pixels<br> 703 * {Number} x: x-axis position in pixels<br> 704 * {Boolean} maximized: true if widget is maximized<br> 705 * {Boolean} showLaunchMenu: true if launch menu is opened on dashboard<br> 706 * <br> 707 * @param {Function} cfg.onSuccess Callback function to capture the success result. Callback parameter is json representation of a Dashboard. 708 * This method will be passed the dashboard object which has the following properties:<br> 709 * <br> 710 * {Boolean} alteredByAdmin: true if altered by an administrator<br> 711 * {Date} createdDate: date dashboard was created<br> 712 * {Boolean} isGroupDashboard: true if dashboard is a group dashboard<br> 713 * {String} layout: layout of dashboard<br> 714 * {Boolean} isdefault: true if this is a default dashboard<br> 715 * {String} name: name of dashboard<br> 716 * {Number} columnCount: number of columns if dashboard is a portal type<br> 717 * {Object} user: the dashoard owner. Has the following properties:<br> 718 * {String} userId: unique user identifier<br> 719 * {List} EDashboardLayoutList: list of dashboard types<br> 720 * {String} defaultSettings: JSON string of default settings which varies by dashboard type<br> 721 * {Object} createdBy: dashboard creator. Has the following properties:<br> 722 * {String} userId: unique user identifier<br> 723 * {String} userRealName: user's name<br> 724 * {Date} editedDate: date dashboard was last edited<br> 725 * {Array} groups: groups dashboard is assigned to<br> 726 * {String} description: description of dashboard<br> 727 * {String} guid: uniqued dashboard identifier<br> 728 * {Array} state: array of widget state objects. Has the following properties:<br> 729 * {String} widgetGuid: unique widget identifier<br> 730 * {Number} width: width of widget in pixels<br> 731 * {Number} zIndex: in pixels<br> 732 * {String} region: containing region on dashboard. Dashboard type specific.<br> 733 * {Boolean} pinned: true if widget is pinned open<br> 734 * {String} buttonId: identifier of button that opens widget<br> 735 * {Number} height: height of widget in pixels<br> 736 * {Number} columnPos: position of widget in a column<br> 737 * {String} name: widget name<br> 738 * {Number} statePosition<br> 739 * {Boolean} active: true if this widget is the active (has focus) widget<br> 740 * {String} uniqueId: unique widget identifier on dashboard<br> 741 * {Boolean} minimized: true if widget is minimized<br> 742 * {Boolean} buttonOpened: true if button launched widget is opened<br> 743 * {Boolean} collapsed: true if widget is collapsed<br> 744 * {Number} y: y-axis position in pixels<br> 745 * {Number} x: x-axis position in pixels<br> 746 * {Boolean} maximized: true if widget is maximized<br> 747 * {Boolean} showLaunchMenu: true if launch menu is opened on dashboard<br> 748 * <br> 749 * @param {Function} [cfg.onFailure] Callback to execute if there is an error (optional, a default alert provided). Callback parameter is an error string. 750 * @example 751 * 752 * var onSuccess = function(dashboard) { 753 * alert(dashboard.name); 754 * }; 755 * 756 * var onFailure = function(error) { 757 * alert(error); 758 * }; 759 * 760 * var dashboard = { 761 * alteredByAdmin: 'false', 762 * createdDate: '04/18/2012 11:29 AM EDT', 763 * isGroupDashboard: false, 764 * layout: 'desktop', 765 * isdefault: false, 766 * name: 'My Dashboard', 767 * columnCount: 0, 768 * user: { 769 * userId: 'testAdmin1', 770 * }, 771 * EDashboardLayoutList: ['accordion', 'desktop', 'portal', 'tabbed'], 772 * defaultSettings: {}, 773 * createdBy: { 774 * userId: 'testAdmin1', 775 * userRealName: 'Test Admin 1' 776 * }, 777 * editedDate: '04/18/2012 11:29 AM EDT', 778 * groups: [], 779 * description: 'This is my dashboard', 780 * guid: guid.util.guid(), 781 * state: [], 782 * showLaunchMenu: false 783 * }; 784 * 785 * Ozone.pref.PrefServer.cloneDashboard({ 786 * json: dashboard, 787 * onSuccess: onSuccess, 788 * onFailure: onFailure 789 * }); 790 */ 791 cloneDashboard : function (cfg){ 792 cfg.url = _url + "/" + 'dashboard' + "/" + cfg.json.guid; 793 var postParams = generateDashboardPostParamsJSON(cfg.json); 794 postParams.cloned = true; 795 cfg.method = 'POST'; 796 cfg.jsonObject = postParams; 797 setValuesViaJSONObject(cfg); 798 }, 799 800 /** 801 * @description Saves changes to existing dashboards 802 * @param {Object} cfg config object see below for properties 803 * @param {Array} cfg.viewsToUpdate array of JSON objects containing the view guid and data to be updated 804 * @param {Array} cfg.viewGuidsToDelete array of guids of views to be deleted 805 * @param {Boolean} cfg.updateOrder flag to update order 806 * @param {Function} cfg.onSuccess callback function to capture the success result 807 * @param {Function} [cfg.onFailure] callback to execute if there is an error (optional, a default alert provided) 808 */ 809 updateAndDeleteDashboards : function (cfg){ 810 cfg.url = _url + "/dashboard"; 811 var postParams = { 812 '_method': 'PUT', 813 'viewsToUpdate': Ozone.util.toString(cfg.viewsToUpdate), 814 'viewGuidsToDelete': Ozone.util.toString(cfg.viewGuidsToDelete), 815 'updateOrder': cfg.updateOrder 816 }; 817 818 cfg.method = 'POST'; 819 cfg.content = postParams; 820 Ozone.util.Transport.send(cfg); 821 }, 822 823 /** 824 * @description Deletes the dashboard with the specified id 825 * @param {Object} cfg config object see below for properties 826 * @param {String} cfg.dashboardId Unigue dashbard identifier 827 * @param {Function} cfg.onSuccess Callback function to capture the success result. Callback parameter is json representation of a Dashboard. 828 * This method will be passed the dashboard object which has the following properties:<br> 829 * <br> 830 * {Boolean} alteredByAdmin: true if altered by an administrator<br> 831 * {Date} createdDate: date dashboard was created<br> 832 * {Boolean} isGroupDashboard: true if dashboard is a group dashboard<br> 833 * {String} layout: layout of dashboard<br> 834 * {Boolean} isdefault: true if this is a default dashboard<br> 835 * {String} name: name of dashboard<br> 836 * {Number} columnCount: number of columns if dashboard is a portal type<br> 837 * {Object} user: the dashoard owner. Has the following properties:<br> 838 * {String} userId: unique user identifier<br> 839 * {List} EDashboardLayoutList: list of dashboard types<br> 840 * {String} defaultSettings: JSON string of default settings which varies by dashboard type<br> 841 * {Object} createdBy: dashboard creator. Has the following properties:<br> 842 * {String} userId: unique user identifier<br> 843 * {String} userRealName: user's name<br> 844 * {Date} editedDate: date dashboard was last edited<br> 845 * {Array} groups: groups dashboard is assigned to<br> 846 * {String} description: description of dashboard<br> 847 * {String} guid: uniqued dashboard identifier<br> 848 * {Array} state: array of widget state objects. Has the following properties:<br> 849 * {String} widgetGuid: unique widget identifier<br> 850 * {Number} width: width of widget in pixels<br> 851 * {Number} zIndex: in pixels<br> 852 * {String} region: containing region on dashboard. Dashboard type specific.<br> 853 * {Boolean} pinned: true if widget is pinned open<br> 854 * {String} buttonId: identifier of button that opens widget<br> 855 * {Number} height: height of widget in pixels<br> 856 * {Number} columnPos: position of widget in a column<br> 857 * {String} name: widget name<br> 858 * {Number} statePosition<br> 859 * {Boolean} active: true if this widget is the active (has focus) widget<br> 860 * {String} uniqueId: unique widget identifier on dashboard<br> 861 * {Boolean} minimized: true if widget is minimized<br> 862 * {Boolean} buttonOpened: true if button launched widget is opened<br> 863 * {Boolean} collapsed: true if widget is collapsed<br> 864 * {Number} y: y-axis position in pixels<br> 865 * {Number} x: x-axis position in pixels<br> 866 * {Boolean} maximized: true if widget is maximized<br> 867 * {Boolean} showLaunchMenu: true if launch menu is opened on dashboard<br> 868 * <br> 869 * @param {Function} [cfg.onFailure] Callback to execute if there is an error (optional, a default alert provided). Callback parameter is an error string. 870 * @example 871 * 872 * var onSuccess = function(dashboard) { 873 * alert(dashboard.name); 874 * }; 875 * 876 * var onFailure = function(error) { 877 * alert(error); 878 * }; 879 * 880 * Ozone.pref.PrefServer.deleteDashboard({ 881 * dashboardId:'917b4cd0-ecbd-410b-afd9-42d150c26426', 882 * onSuccess:onSuccess, 883 * onFailure:onFailure 884 * }); 885 */ 886 deleteDashboard : function (cfg){ 887 cfg.url = _url + "/dashboard/" + cfg.dashboardId; 888 deleteBase(cfg); 889 }, 890 891 /** 892 * @description Returns all dashboards for the logged in user. 893 * @param {Object} cfg config object see below for properties 894 * @param {Function} cfg.onSuccess Callback function to capture the success result. 895 * This method is passed an object having the following properties:<br> 896 * <br> 897 * {Boolean} success: true if dashboards found<br> 898 * {Number} results: number of dashboards found<br> 899 * {Array} data: array of dashboards objects found. Dashboard object has the following properties:<br> 900 * <br> 901 * {Boolean} alteredByAdmin: true if altered by an administrator<br> 902 * {Date} createdDate: date dashboard was created<br> 903 * {Boolean} isGroupDashboard: true if dashboard is a group dashboard<br> 904 * {String} layout: layout of dashboard<br> 905 * {Boolean} isdefault: true if this is a default dashboard<br> 906 * {String} name: name of dashboard<br> 907 * {Number} columnCount: number of columns if dashboard is a portal type<br> 908 * {Object} user: the dashoard owner. Has the following properties:<br> 909 * {String} userId: unique user identifier<br> 910 * {List} EDashboardLayoutList: list of dashboard types<br> 911 * {String} defaultSettings: JSON string of default settings which varies by dashboard type<br> 912 * {Object} createdBy: dashboard creator. Has the following properties:<br> 913 * {String} userId: unique user identifier<br> 914 * {String} userRealName: user's name<br> 915 * {Date} editedDate: date dashboard was last edited<br> 916 * {Array} groups: groups dashboard is assigned to<br> 917 * {String} description: description of dashboard<br> 918 * {String} guid: uniqued dashboard identifier<br> 919 * {Array} state: array of widget state objects. Has the following properties:<br> 920 * {String} widgetGuid: unique widget identifier<br> 921 * {Number} width: width of widget in pixels<br> 922 * {Number} zIndex: in pixels<br> 923 * {String} region: containing region on dashboard. Dashboard type specific.<br> 924 * {Boolean} pinned: true if widget is pinned open<br> 925 * {String} buttonId: identifier of button that opens widget<br> 926 * {Number} height: height of widget in pixels<br> 927 * {Number} columnPos: position of widget in a column<br> 928 * {String} name: widget name<br> 929 * {Number} statePosition<br> 930 * {Boolean} active: true if this widget is the active (has focus) widget<br> 931 * {String} uniqueId: unique widget identifier on dashboard<br> 932 * {Boolean} minimized: true if widget is minimized<br> 933 * {Boolean} buttonOpened: true if button launched widget is opened<br> 934 * {Boolean} collapsed: true if widget is collapsed<br> 935 * {Number} y: y-axis position in pixels<br> 936 * {Number} x: x-axis position in pixels<br> 937 * {Boolean} maximized: true if widget is maximized<br> 938 * {Boolean} showLaunchMenu: true if launch menu is opened on dashboard<br> 939 * <br> 940 * <br> 941 * @param {Function} [cfg.onFailure] Callback to execute if there is an error (optional, a default alert provided). Callback parameter is an error string. 942 * @example 943 * 944 * var onSuccess = function(obj) { 945 * alert(obj.results); 946 * if (obj.results > 0) { 947 * for (var i = 0; i < obj.results; i++) { 948 * alert(obj.data[i].name); 949 * } 950 * } 951 * }; 952 * 953 * var onFailure = function(error) { 954 * alert(error); 955 * }; 956 * 957 * Ozone.pref.PrefServer.findDashboards({ 958 * onSuccess:onSuccess, 959 * onFailure:onFailure 960 * }); 961 */ 962 findDashboards : function (cfg){ 963 cfg.url = "dashboard"; 964 list(cfg); 965 }, 966 967 /** 968 * @description Returns all dashboards for the logged in user filtered by the type of dashboard. 969 * @param {Object} cfg config object see below for properties 970 * @param {String} cfg.type A string representing the type of dashboard. If using built in dashboard types, this would include desktop, tabbed, portal, and accordion. 971 * @param {Function} cfg.onSuccess Callback function to capture the success result. 972 * This method is passed an object having the following properties:<br> 973 * <br> 974 * {Boolean} success: true if dashboards found<br> 975 * {Number} results: number of dashboards found<br> 976 * {Array} data: array of dashboards objects found. Dashboard object has the following properties:<br> 977 * <br> 978 * {Boolean} alteredByAdmin: true if altered by an administrator<br> 979 * {Date} createdDate: date dashboard was created<br> 980 * {Boolean} isGroupDashboard: true if dashboard is a group dashboard<br> 981 * {String} layout: layout of dashboard<br> 982 * {Boolean} isdefault: true if this is a default dashboard<br> 983 * {String} name: name of dashboard<br> 984 * {Number} columnCount: number of columns if dashboard is a portal type<br> 985 * {Object} user: the dashoard owner. Has the following properties:<br> 986 * {String} userId: unique user identifier<br> 987 * {List} EDashboardLayoutList: list of dashboard types<br> 988 * {String} defaultSettings: JSON string of default settings which varies by dashboard type<br> 989 * {Object} createdBy: dashboard creator. Has the following properties:<br> 990 * {String} userId: unique user identifier<br> 991 * {String} userRealName: user's name<br> 992 * {Date} editedDate: date dashboard was last edited<br> 993 * {Array} groups: groups dashboard is assigned to<br> 994 * {String} description: description of dashboard<br> 995 * {String} guid: uniqued dashboard identifier<br> 996 * {Array} state: array of widget state objects. Has the following properties:<br> 997 * {String} widgetGuid: unique widget identifier<br> 998 * {Number} width: width of widget in pixels<br> 999 * {Number} zIndex: in pixels<br> 1000 * {String} region: containing region on dashboard. Dashboard type specific.<br> 1001 * {Boolean} pinned: true if widget is pinned open<br> 1002 * {String} buttonId: identifier of button that opens widget<br> 1003 * {Number} height: height of widget in pixels<br> 1004 * {Number} columnPos: position of widget in a column<br> 1005 * {String} name: widget name<br> 1006 * {Number} statePosition<br> 1007 * {Boolean} active: true if this widget is the active (has focus) widget<br> 1008 * {String} uniqueId: unique widget identifier on dashboard<br> 1009 * {Boolean} minimized: true if widget is minimized<br> 1010 * {Boolean} buttonOpened: true if button launched widget is opened<br> 1011 * {Boolean} collapsed: true if widget is collapsed<br> 1012 * {Number} y: y-axis position in pixels<br> 1013 * {Number} x: x-axis position in pixels<br> 1014 * {Boolean} maximized: true if widget is maximized<br> 1015 * {Boolean} showLaunchMenu: true if launch menu is opened on dashboard<br> 1016 * <br> 1017 * <br> 1018 * @param {Function} [cfg.onFailure] Callback to execute if there is an error (optional, a default alert provided). Callback parameter is an error string. 1019 * @example 1020 * 1021 * var onSuccess = function(obj) { 1022 * alert(obj.results); 1023 * if (obj.results > 0) { 1024 * for (var i = 0; i < obj.results; i++) { 1025 * alert(obj.data[i].name); 1026 * } 1027 * } 1028 * }; 1029 * 1030 * var onFailure = function(error) { 1031 * alert(error); 1032 * }; 1033 * 1034 * Ozone.pref.PrefServer.findDashboardsByType({ 1035 * type:'desktop', 1036 * onSuccess:onSuccess, 1037 * onFailure:onFailure 1038 * }); 1039 */ 1040 findDashboardsByType : function (cfg){ 1041 cfg.url = "dashboard?layout=" + cfg.type; 1042 list(cfg); 1043 }, 1044 1045 /** 1046 * @description Gets the widget with the specified id 1047 * @param {Object} cfg config object see below for properties 1048 * @param {String} cfg.widgetId The guid of the widget. 1049 * @param {String} cfg.universalName The universal name for the widget. 1050 * @param {Function} cfg.onSuccess Callback function to capture the success result. Callback is passed the following object as a parameter: {id:Number, namespace:String, value:Object, path:String} 1051 * This method is passed an object having the following properties:<br> 1052 * <br> 1053 * {Number} id: database pk identifier<br> 1054 * {String} namespace: "widget"<br> 1055 * {Object} value: widget object having the following properties:<br> 1056 * <br> 1057 * {Boolean} editable: true if widget can be edited<br> 1058 * {Boolean} visible: true if widget is visible<br> 1059 * {Number} position<br> 1060 * {String} userId: widget owner identifier<br> 1061 * {String} userRealName: widget owner name<br> 1062 * {String} namespace: widget name<br> 1063 * {String} url: url of widget application<br> 1064 * {String} headerIcon: url of widget header icon<br> 1065 * {String} image: url of widget image<br> 1066 * {String} smallIconUrl: url of widget's small icon<br> 1067 * {String} largeIconUrl: url of widget's large icon<br> 1068 * {Number} width: width of the widget in pixels<br> 1069 * {Number} height: height of the widget in pixels<br> 1070 * {Number} x: x-axis position<br> 1071 * {Number} y: y-axis position<br> 1072 * {Boolean} minimized: true if widget is minimized<br> 1073 * {Boolean} maximized: true if widget is maximized<br> 1074 * {String} widgetVersion: widget version<br> 1075 * {Array} tags: array of tag strings<br> 1076 * {Boolean} definitionVisible: true if definition is visible<br> 1077 * {Boolean} singleton: true if widget is a singleton<br> 1078 * {Boolean} background: true if widget runs in the background<br> 1079 * {Array} allRequired: array of all widgets required by this widget<br> 1080 * {Array} directRequired: array of all widgets directly required by this widget<br> 1081 * {Array} widgetTypes: array of widget types this widget belongs to<br> 1082 * <br> 1083 * {String} path: The guid of the widget.<br> 1084 * <br> 1085 * @param {Function} [cfg.onFailure] Callback to execute if there is an error (optional, a default alert provided). Callback parameter is an error string. 1086 * @example 1087 * 1088 * var onSuccess = function(obj) { 1089 * if (obj.value) { 1090 * alert(obj.value.namespace); 1091 * } 1092 * }; 1093 * 1094 * var onFailure = function(error) { 1095 * alert(error); 1096 * }; 1097 * 1098 * Ozone.pref.PrefServer.getWidget({ 1099 * widgetId:'ea5435cf-4021-4f2a-ba69-dde451d12551', 1100 * widgetUuid: 'com.company.widget.name', 1101 * onSuccess:onSuccess, 1102 * onFailure:onFailure 1103 * }); 1104 */ 1105 getWidget : function (cfg){ 1106 cfg.url = _url + "/" + 'widget' + "/" + cfg.widgetId; 1107 if(cfg.universalName) { 1108 cfg.url += '?universalName=' + cfg.universalName; 1109 } 1110 get(cfg); 1111 }, 1112 1113 /** 1114 * @description Gets all widgets for a given user. 1115 * @param {Object} cfg config object see below for properties 1116 * @param {Boolean} [cfg.userOnly] boolean flag that determines whether to only return widgets assigned to the user (excluding widgets to which the user only has access via their assigned groups) 1117 * @param {Object} [cfg.searchParams] object containing search parameters 1118 * @param {String} [cfg.searchParams.widgetName] name of widget '%' are wildcards 1119 * @param {String} [cfg.searchParams.widgetNameExactMatch] true or false to match the name exactly. defaults to false 1120 * @param {String} [cfg.searchParams.widgetVersion] version of widget '%' are wildcards 1121 * @param {String} [cfg.searchParams.widgetGuid] Guid of widget '%' are wildcards 1122 * @param {String} [cfg.searchParams.universalName] Universal name of widget '%' are wildcards 1123 * @param {Function} cfg.onSuccess callback function to capture the success result. 1124 * This method is passed an array of objects having the following properties:<br> 1125 * <br> 1126 * {Number} id: database pk identifier<br> 1127 * {String} namespace: "widget"<br> 1128 * {Object} value: widget object having the following properties:<br> 1129 * <br> 1130 * {Boolean} editable: true if widget can be edited<br> 1131 * {Boolean} visible: true if widget is visible<br> 1132 * {Number} position<br> 1133 * {String} userId: widget owner identifier<br> 1134 * {String} userRealName: widget owner name<br> 1135 * {String} namespace: widget name<br> 1136 * {String} url: url of widget application<br> 1137 * {String} headerIcon: url of widget header icon<br> 1138 * {String} image: url of widget image<br> 1139 * {String} smallIconUrl: url of widget's small icon<br> 1140 * {String} largeIconUrl: url of widget's large icon<br> 1141 * {Number} width: width of the widget in pixels<br> 1142 * {Number} height: height of the widget in pixels<br> 1143 * {Number} x: x-axis position<br> 1144 * {Number} y: y-axis position<br> 1145 * {Boolean} minimized: true if widget is minimized<br> 1146 * {Boolean} maximized: true if widget is maximized<br> 1147 * {String} widgetVersion: widget version<br> 1148 * {Array} tags: array of tag strings<br> 1149 * {Boolean} definitionVisible: true if definition is visible<br> 1150 * {Boolean} singleton: true if widget is a singleton<br> 1151 * {Boolean} background: true if widget runs in the background<br> 1152 * {Array} allRequired: array of all widgets required by this widget<br> 1153 * {Array} directRequired: array of all widgets directly required by this widget<br> 1154 * {Array} widgetTypes: array of widget types this widget belongs to<br> 1155 * <br> 1156 * {String} path: The guid of the widget.<br> 1157 * <br> 1158 * @param {Function} [cfg.onFailure] callback to execute if there is an error (optional, a default alert provided). This callback is called with two parameters: a error message string, and optionally a status code 1159 * @example 1160 * 1161 * var onSuccess = function(widgets) { 1162 * if (widgets.length > 0) { 1163 * alert(widgets[0].value.namespace); 1164 * } 1165 * }; 1166 * 1167 * var onFailure = function(error, status) { 1168 * alert(error); 1169 * }; 1170 * 1171 * Ozone.pref.PrefServer.findWidgets({ 1172 * onSuccess:onSuccess, 1173 * onFailure:onFailure 1174 * }); 1175 */ 1176 findWidgets : function (cfg){ 1177 1178 cfg.url = _url + "/widget"; 1179 if (!cfg.userOnly) { 1180 cfg.url += "/listUserAndGroupWidgets"; 1181 } 1182 1183 // Add search params 1184 var postParams = { 1185 '_method': 'GET' 1186 }; 1187 1188 if (cfg.searchParams) { 1189 if (cfg.searchParams.widgetName && cfg.searchParams.widgetName.length > 0) { 1190 var searchTerm = cfg.searchParams.widgetName; 1191 if (!cfg.searchParams.widgetNameExactMatch) { 1192 searchTerm = '%'+searchTerm+'%'; 1193 } 1194 postParams['widgetName'] = searchTerm; 1195 } 1196 if (cfg.searchParams.widgetVersion && cfg.searchParams.widgetVersion.length > 0) { 1197 postParams['widgetVersion'] = cfg.searchParams.widgetVersion; 1198 } 1199 if (cfg.searchParams.widgetGuid && cfg.searchParams.widgetGuid.length > 0) { 1200 postParams['widgetGuid'] = cfg.searchParams.widgetGuid; 1201 } 1202 if (cfg.searchParams.universalName && cfg.searchParams.universalName.length > 0) { 1203 postParams['universalName'] = cfg.searchParams.universalName; 1204 } 1205 if (cfg.searchParams.group_id) { 1206 postParams['group_id'] = cfg.searchParams.group_id; 1207 } 1208 } 1209 1210 cfg.method = 'POST'; 1211 cfg.content = postParams; 1212 Ozone.util.Transport.send(cfg); 1213 }, 1214 1215 /** 1216 * @description Saves changes to existing widgets 1217 * @param {Object} cfg config object see below for properties 1218 * @param {Array} cfg.widgetsToUpdate array of JSON objects containing the widget guid and data to be updated 1219 * @param {Array} cfg.widgetGuidsToDelete array of guids of widgets to be deleted 1220 * @param {Boolean} cfg.updateOrder flag to update order 1221 * @param {Function} cfg.onSuccess callback function to capture the success result 1222 * @param {Function} [cfg.onFailure] callback to execute if there is an error (optional, a default alert provided) 1223 */ 1224 updateAndDeleteWidgets : function (cfg){ 1225 cfg.url = _url + "/widget"; 1226 var postParams = { 1227 '_method': 'PUT', 1228 'widgetsToUpdate': Ozone.util.toString(cfg.widgetsToUpdate), 1229 'widgetGuidsToDelete': Ozone.util.toString(cfg.widgetGuidsToDelete), 1230 'updateOrder': cfg.updateOrder 1231 }; 1232 1233 cfg.method = 'POST'; 1234 cfg.content = postParams; 1235 Ozone.util.Transport.send(cfg); 1236 }, 1237 1238 /** 1239 * @description Retrieves the user preference for the provided name and namespace 1240 * @param {Object} cfg config object see below for properties 1241 * @param {String} cfg.namespace The namespace of the requested user preference 1242 * @param {String} cfg.name The name of the requested user preference 1243 * @param {Function} cfg.onSuccess The function to be called if the user preference is successfully retrieved from 1244 * the database. This function takes a single argument, which is a JSON object. If a preference is found, the 1245 * complete JSON structure as shown below will be returned. If it is not found this function be passed an empty JSON object. 1246 * @example 1247 * The following is an example of a complete preference object passed to the onSuccess 1248 * function: 1249 * { 1250 * "value":"true", 1251 * "path":"militaryTime", 1252 * "user": 1253 * { 1254 * "userId":"testAdmin1" 1255 * }, 1256 * "namespace":"com.mycompany.AnnouncingClock" 1257 * } 1258 * @param {Function} [cfg.onFailure] This parameter is optional. If this function is not specified a default error 1259 * message will be displayed.This function is called if an error occurs on preference retrieval. It is not 1260 * called if the preference is simply missing. 1261 * This function should accept two arguments:<br> 1262 * <br> 1263 * error: String<br> 1264 * The error message<br> 1265 * <br> 1266 * Status: The numeric HTTP Status code (if applicable)<br> 1267 * 401: You are not authorized to access this entity.<br> 1268 * 500: An unexpected error occurred.<br> 1269 * 404: The user preference was not found.<br> 1270 * 400: The requested entity failed to pass validation.<br> 1271 * @example 1272 * The following shows how to make a call to getUserPreference: 1273 * function onSuccess(pref){ 1274 * alert(Ozone.util.toString(pref.value)); 1275 * } 1276 * 1277 * function onFailure(error,status){ 1278 * alert('Error ' + error); 1279 * alert(status); 1280 * } 1281 * 1282 * // The following code calls getUserPreference with the above defined onSuccess and 1283 * // onFailure callbacks. 1284 * Ozone.pref.PrefServer.getUserPreference({ 1285 * namespace:'com.company.widget', 1286 * name:'First President', 1287 * onSuccess:onSuccess, 1288 * onFailure:onFailure 1289 * }); 1290 */ 1291 getUserPreference : function (cfg){ 1292 cfg.url = _url + "/preference/" + cfg.namespace + "/" + cfg.name; 1293 1294 //igonore 404 error code, onSuccess will be called with emtpy object payload 1295 cfg.ignoredErrorCodes = [404]; 1296 get(cfg); 1297 }, 1298 1299 /** 1300 * @description Checks for the existence of a user preference for a given namespace and name 1301 * @param {Object} cfg config object see below for properties 1302 * @param {String} cfg.namespace The namespace of the requested user 1303 * @param {String} cfg.name The name of the requested user 1304 * @param {Function} cfg.onSuccess The callback function that is called if a preference successfully return from the database. 1305 * This method is passed an object having the following properties:<br> 1306 * <br> 1307 * {Number} statusCode: status code<br> 1308 * {Boolean} preferenceExist: true if preference exists<br> 1309 * <br> 1310 * @param {Function} [cfg.onFailure] The callback function that is called if the preference could not be found in the database. Callback parameter is an error string. 1311 * @example 1312 * 1313 * var onSuccess = function(obj) { 1314 * if (obj.statusCode = 200) { 1315 * alert(obj.preferenceExist); 1316 * } 1317 * }; 1318 * 1319 * var onFailure = function(error) { 1320 * alert(error); 1321 * }; 1322 * 1323 * Ozone.pref.PrefServer.doesUserPreferenceExist({ 1324 * namespace:'foo.bar.0', 1325 * name:'test path entry 0', 1326 * onSuccess:onSuccess, 1327 * onFailure:onFailure 1328 * }); 1329 */ 1330 doesUserPreferenceExist: function(cfg) { 1331 cfg.url = _url + "/hasPreference/" + cfg.namespace + "/" + cfg.name; 1332 get(cfg); 1333 }, 1334 1335 /** 1336 * @description retrieves the current user logged into the system 1337 * @param {Object} cfg config object see below for properties 1338 * @param {Function} cfg.onSuccess The callback function that is called for a successful retrieval of the user logged in. 1339 * This method is passed an object having the following properties:<br> 1340 * <br> 1341 * {String} currentUserName: user name<br> 1342 * {String} currentUser: user real name<br> 1343 * {Date} currentUserPrevLogin: previous login date<br> 1344 * {Number} currentId: database pk index<br> 1345 * <br> 1346 * @param {Function} cfg.[onFailure] The callback function that is called when the system is unable to retrieve the current user logged in. Callback parameter is an error string. 1347 * @example 1348 * 1349 * var onSuccess = function(obj) { 1350 * if (obj) { 1351 * alert(obj.currentUser); 1352 * } 1353 * }; 1354 * 1355 * var onFailure = function(error) { 1356 * alert(error); 1357 * }; 1358 * 1359 * Ozone.pref.PrefServer.getCurrentUser({ 1360 * onSuccess:onSuccess, 1361 * onFailure:onFailure 1362 * }); 1363 */ 1364 getCurrentUser: function(cfg) { 1365 cfg.url = _url + "/person/whoami"; 1366 get(cfg); 1367 }, 1368 1369 /** 1370 * @description For retrieving the OWF system server version 1371 * @param {Object} cfg config object see below for properties 1372 * @param {Function} cfg.onSuccess The callback function that is called for successfully retrieving the server version of the OWF system. 1373 * This method is passed an object having the following properties:<br> 1374 * <br> 1375 * {String} {serverVersion: server version<br> 1376 * <br> 1377 * @param {Function} [cfg.onFailure] The callback function that is called when the system fails to retrieve the server version of the OWF system. Callback parameter is an error string. 1378 * @example 1379 * 1380 * var onSuccess = function(obj) { 1381 * if (obj) { 1382 * alert(obj.serverVersion); 1383 * } 1384 * }; 1385 * 1386 * var onFailure = function(error) { 1387 * alert(error); 1388 * }; 1389 * 1390 * Ozone.pref.PrefServer.getServerVersion({ 1391 * onSuccess:onSuccess, 1392 * onFailure:onFailure 1393 * }); 1394 */ 1395 getServerVersion: function(cfg) { 1396 cfg.url = _url + "/server/resources"; 1397 get(cfg); 1398 }, 1399 1400 /** 1401 * @description Creates or updates a user preference for the provided namespace and name. 1402 * @param {Object} cfg config object see below for properties 1403 * @param {String} cfg.namespace The namespace of the user preference 1404 * @param {String} cfg.name The name of the user preference 1405 * @param {String} cfg.value The value of the user preference. The value can be any string including JSON. 1406 * @param {Function} cfg.onSuccess The function to be called if the user preference is successfully updated in 1407 * the database. 1408 * @example 1409 * The following is an example of a complete preference object passed to the onSuccess 1410 * function: 1411 * { 1412 * "value":"true", 1413 * "path":"militaryTime", 1414 * "user": 1415 * { 1416 * "userId":"testAdmin1" 1417 * }, 1418 * "namespace":"com.mycompany.AnnouncingClock" 1419 * } 1420 * @param {Function} [cfg.onFailure] The function to be called if the user preference cannot be stored in the database. 1421 * If this function is not specified a default error message will be displayed. This function is passed 1422 * back the following parameters:<br> 1423 * <br> 1424 * error: String<br> 1425 * The error message<br> 1426 * <br> 1427 * Status: The HTTP Status code<br> 1428 * 401: You are not authorized to access this entity.<br> 1429 * 500: An unexpected error occurred.<br> 1430 * 404: The requested entity was not found.<br> 1431 * 400: The requested entity failed to pass validation.<br> 1432 * @example 1433 * 1434 * function onSuccess(pref){ 1435 * alert(pref.value); 1436 * } 1437 * 1438 * function onFailure(error,status){ 1439 * alert('Error ' + error); 1440 * alert(status); 1441 * } 1442 * 1443 * var text = 'George Washington'; 1444 * Ozone.pref.PrefServer.setUserPreference({ 1445 * namespace:'com.company.widget', 1446 * name:'First President', 1447 * value:text, 1448 * onSuccess:onSuccess, 1449 * onFailure:onFailure 1450 * }); 1451 */ 1452 setUserPreference : function (cfg) { 1453 cfg.url = _url + "/preference/" + cfg.namespace + "/" + cfg.name; 1454 if (cfg.method == null) { 1455 cfg.method = 'PUT'; 1456 } 1457 cfg.content = { 1458 '_method': cfg.method, 1459 'value': cfg.value 1460 }; 1461 1462 if (cfg.onSuccess) { 1463 if (!cfg.onFailure) { //must ensure there is an onfailure method, as we using content 1464 cfg.onFailure = function(err) { 1465 alert(Ozone.util.ErrorMessageString.saveUserPreferences + " : " + err); 1466 }; 1467 } 1468 Ozone.util.Transport.send(cfg); 1469 } else { 1470 Ozone.util.Transport.sendAndForget(cfg); 1471 } 1472 }, 1473 1474 /** 1475 * @description Deletes a user preference with the provided namespace and name. 1476 * @param {Object} cfg config object see below for properties 1477 * @param {String} cfg.namespace The namespace of the user preference 1478 * @param {String} cfg.name The name of the user preference 1479 * @param {Function} cfg.onSuccess The function to be called if the user preference is successfully deleted from the database. 1480 * @example 1481 * The following is an example of a complete preference object passed to the onSuccess 1482 * function: 1483 * 1484 * { 1485 * "value":"true", 1486 * "path":"militaryTime", 1487 * "user": 1488 * { 1489 * "userId":"testAdmin1" 1490 * }, 1491 * "namespace":"com.mycompany.AnnouncingClock" 1492 * } 1493 * @param {Function} [cfg.onFailure] The function to be called if the user preference cannot be deleted from the 1494 * database or if the preference does not exist. If this function is not specified a default error message will be 1495 * displayed. This function is passed back the following parameters: <br> 1496 * <br> 1497 * error: String <br> 1498 * The error message <br> 1499 * <br> 1500 * Status: The HTTP Status code<br> 1501 * <br> 1502 * 401: You are not authorized to access this entity.<br> 1503 * 500: An unexpected error occurred.<br> 1504 * 404: The user preference was not found.<br> 1505 * 400: The requested entity failed to pass validation. <br> 1506 * <br> 1507 * @example 1508 * function onSuccess(pref){ 1509 * alert(pref.value); 1510 * } 1511 * 1512 * function onFailure(error,status){ 1513 * alert('Error ' + error); 1514 * alert(status); 1515 * } 1516 * 1517 * Ozone.pref.PrefServer.deleteUserPreference({ 1518 * namespace:'com.company.widget', 1519 * name:'First President', 1520 * onSuccess:onSuccess, 1521 * onFailure:onFailure 1522 * }); 1523 */ 1524 deleteUserPreference : function (cfg){ 1525 cfg.method = "DELETE"; 1526 //igonore 404 error code, onSuccess will be called with null payload 1527 cfg.ignoredErrorCodes = [404]; 1528 cfg.path = cfg.name; 1529 Ozone.pref.PrefServer.setUserPreference(cfg); 1530 }, 1531 1532 /** 1533 * @private 1534 */ 1535 getDependentWidgets : function (cfg) { 1536 cfg.url = _url + '/widgetDefinition/dependents'; 1537 cfg.method = 'POST'; 1538 if (!cfg.content) { cfg.content = {}; } 1539 Ozone.util.Transport.send(cfg); 1540 }, 1541 1542 /** 1543 * @private 1544 */ 1545 getDependentPersonWidgets : function (cfg) { 1546 cfg.url = _url + '/personWidgetDefinition/dependents'; 1547 cfg.method = 'POST'; 1548 if (!cfg.content) { cfg.content = {}; } 1549 Ozone.util.Transport.send(cfg); 1550 }, 1551 1552 /** 1553 * @private 1554 */ 1555 deleteWidgetDefs : function (cfg) { 1556 cfg.url = _url + '/widgetDefinition'; 1557 cfg.method = 'DELETE'; 1558 if (!cfg.content) { cfg.content = {}; } 1559 Ozone.util.Transport.send(cfg); 1560 } 1561 1562 }; 1563 }; 1564 1565 var configParams = Ozone.util.parseWindowNameData(); 1566 var url = null; 1567 if (configParams != null && configParams.preferenceLocation != null) { 1568 url = configParams.preferenceLocation; 1569 } 1570 else { 1571 url = Ozone.config.prefsLocation; 1572 } 1573 1574 Ozone.pref.PrefServer = Ozone.pref.PrefServer(url); 1575 if(url == null) { 1576 for (var fname in Ozone.pref.PrefServer) { 1577 if (typeof Ozone.pref.PrefServer[fname] == 'function') { 1578 //dummyfy 1579 Ozone.pref.PrefServer[fname] = function(){}; 1580 } 1581 } 1582 } 1583 }(window, document));