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 'description': cfg.json.description, 203 'guid': cfg.json.guid, 204 'isdefault': cfg.json.isdefault, 205 'locked': cfg.json.locked, 206 'state': cfg.json.state, 207 'layoutConfig': cfg.json.layoutConfig, 208 'stack': cfg.json.stack 209 }; 210 if (cfg.json.cloned === true) content.cloned = true; 211 if (cfg.json.bypassLayoutRearrange === true) content.bypassLayoutRearrange = true; 212 } 213 cfg.content = content; 214 setValueBase(cfg); 215 }; 216 217 /** 218 * @private 219 * @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. 220 * @param cfg config object see below for properties 221 * @param cfg.url url to be used in the call 222 * @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. 223 * @param cfg.method The method for the call. ('DELETE', 'PUT') 224 * @param cfg.onSuccess callback function to capture the success result (optional) 225 * @param cfg.onFailure callback to execute if there is an error (optional, a default alert is provided if an onSuccess callback is passed in) 226 * @example 227 * 228 * ...code setting up a desktop dashboard 229 * 230 * var postParams = 231 * { 232 * 'value': this.config.value, 233 * 'path': this.config.value.guid, 234 * 'type': 'desktop', 235 * 'isdefault': saveAsDefault 236 * }; 237 * 238 * setValuesViaJSONObject(_url + "/" + namespace + "/" + path, jsonObject, saveMethod, onSuccess, onFailure); 239 */ 240 var setValuesViaJSONObject = function(cfg) { 241 if (cfg.jsonObject._method === undefined) 242 { 243 if (cfg.method == null) { 244 cfg.method = 'PUT'; 245 } 246 cfg.jsonObject._method = cfg.method; 247 } 248 cfg.json = cfg.jsonObject; 249 setValue(cfg); 250 251 }; 252 253 /** 254 * @private 255 * @description Create JSON object with params. This should generally not be called from user code. 256 * @param cfg config object see below for properties 257 * @param cfg.dashboardId 258 * @param cfg.value 259 * @param cfg.type 260 * @param cfg.isDefault 261 * @return the JSON object 262 */ 263 var generateDashboardPostParamsJSON = function (json) { 264 var postParams = { 265 'name': json.name, 266 'description': json.description, 267 'guid': json.guid, 268 'isdefault': json.isdefault, 269 'locked': json.locked, 270 'state': json.state, 271 'layoutConfig': typeof json.layoutConfig === 'string' ? json.layoutConfig : Ozone.util.toString(json.layoutConfig), 272 'stack': json.stack 273 }; 274 return postParams; 275 }; 276 277 return /** @lends Ozone.pref.PrefServer.prototype */{ 278 279 version: Ozone.version.owfversion + Ozone.version.preference, 280 281 /** 282 * @description Get the url for the Preference Server 283 * @returns {String} url 284 */ 285 getUrl : function() { 286 return _url; 287 }, 288 289 /** 290 * @description Sets the url for the Preference Server 291 * @param {String} url 292 * @returns void 293 */ 294 setUrl : function(url) { 295 _url = url; 296 }, 297 298 /** 299 * @description Gets the dashboard with the specified id 300 * @param {Object} cfg config object see below for properties 301 * @param {String} cfg.dashboardId Unigue dashbard identifier 302 * @param {Function} cfg.onSuccess Callback function to capture the success result. Callback parameter is json representation of a dashboard. 303 * This method will be passed the dashboard object which has the following properties:<br> 304 * <br> 305 * {Boolean} alteredByAdmin: true if altered by an administrator<br> 306 * {Date} createdDate: date dashboard was created<br> 307 * {Boolean} isGroupDashboard: true if dashboard is a group dashboard<br> 308 * {Boolean} isdefault: true if this is a default dashboard<br> 309 * {String} name: name of dashboard<br> 310 * {Object} user: the dashoard owner. Has the following properties:<br> 311 * {String} userId: unique user identifier<br> 312 * {Object} createdBy: dashboard creator. Has the following properties:<br> 313 * {String} userId: unique user identifier<br> 314 * {String} userRealName: user's name<br> 315 * {Date} editedDate: date dashboard was last edited<br> 316 * {Array} groups: groups dashboard is assigned to<br> 317 * {String} description: description of dashboard<br> 318 * {String} guid: uniqued dashboard identifier<br> 319 * {String} layoutConfig: Holds the various containers and panes on a dashboard and the widgets inside of the panes, including the widget states. 320 * This parameter provides an EXT JS style configuration used to layout the supported pane types in an OWF dashboard along. Each 321 * internal definition can hold nested panes in an items array, widgets in a widgets array, and default values for those widgets in a defaultValues array. 322 * Panes can have the following parameters:<br> 323 * <ul style="list-style-type:none"> 324 * <li>{String} xtype: container|accordionpane|desktoppane|fitpane|portalpane|tabbedpane|dashboardsplitter</li> 325 * <li>{Number} flex: 1 if for a pane; 3 for a container<li> 326 * <li>{String} htmlText: in pixels (e.g., 300px) or percent (e.g., 100%) or "variable"; valid if nested in a horizontally/vertically split pane</li> 327 * <li>{String} cls: left|right if nested in a horizontally split pane; top|bottom if nested in a vertically split pane; vbox|hbox if xtype is container</li> 328 * <li>{Array} items: an array of 2 nested pane configurations along with a possible dashboardspliiter for vbox and hbox containers; empty otherwise</li> 329 * <li>{String} paneType: accordionpane|desktoppane|fitpane|portalpane|tabbedpane; valid if xtype is not container</li> 330 * <li>{Array} layout: valid only for container xtype. Includes the following elements:</li> 331 * <ul style="list-style-type:none"> 332 * <li>{String} type: vbox|hbox</li> 333 * <li>{String} align: stretch</li> 334 * </ul> 335 * <li>{Array} widgets: array of widget state objects. Each has the following properties:</li> 336 * <ul style="list-style-type:none"> 337 * <li>{String} widgetGuid: unique widget identifier</li> 338 * <li>{Number} width: width of widget in pixels</li> 339 * <li>{Number} zIndex: in pixels</li> 340 * <li>{String} region: containing region on dashboard. Dashboard type specific.</li> 341 * <li>{Boolean} pinned: true if widget is pinned open</li> 342 * <li>{String} buttonId: identifier of button that opens widget</li> 343 * <li>{Number} height: height of widget in pixels</li> 344 * <li>{Number} columnPos: position of widget in a column</li> 345 * <li>{String} name: widget name</li> 346 * <li>{Number} statePosition</li> 347 * <li>{Boolean} active: true if this widget is the active (has focus) widget</li> 348 * <li>{String} uniqueId: unique widget identifier on dashboard</li> 349 * <li>{Boolean} minimized: true if widget is minimized</li> 350 * <li>{Boolean} buttonOpened: true if button launched widget is opened</li> 351 * <li>{Boolean} collapsed: true if widget is collapsed</li> 352 * <li>{Number} y: y-axis position in pixels</li> 353 * <li>{Number} x: x-axis position in pixels</li> 354 * <li>{Boolean} maximized: true if widget is maximized</li> 355 * </ul> 356 * <li>{String} defaultSettings: JSON string of default settings which varies by pane type; not valid for containers</li> 357 * </ul> 358 * <br> 359 * @param {Function} [cfg.onFailure] Callback to execute if there is an error (optional, a default alert provided). Callback parameter is an error string. 360 * @example 361 * 362 * var onSuccess = function(dashboard) { 363 * alert(dashboard.name); 364 * }; 365 * 366 * var onFailure = function(error) { 367 * alert(error); 368 * }; 369 * 370 * Ozone.pref.PrefServer.getDashboard({ 371 * dashboardId:'917b4cd0-ecbd-410b-afd9-42d150c26426', 372 * onSuccess:onSuccess, 373 * onFailure:onFailure 374 * }); 375 */ 376 getDashboard : function (cfg){ 377 cfg.url = _url + "/" + 'dashboard' + "/" + cfg.dashboardId; 378 get(cfg); 379 }, 380 381 /** 382 * @description Gets the user's default dashboard 383 * @param {Object} cfg config object see below for properties 384 * @param {Function} cfg.onSuccess Callback function to capture the success result. Callback parameter is json representation of a Dashboard. 385 * This method will be passed the dashboard object which has the following properties:<br> 386 * <br> 387 * {Boolean} alteredByAdmin: true if altered by an administrator<br> 388 * {Date} createdDate: date dashboard was created<br> 389 * {Boolean} isGroupDashboard: true if dashboard is a group dashboard<br> 390 * {Boolean} isdefault: true if this is a default dashboard<br> 391 * {String} name: name of dashboard<br> 392 * {Object} user: the dashoard owner. Has the following properties:<br> 393 * {String} userId: unique user identifier<br> 394 * {Object} createdBy: dashboard creator. Has the following properties:<br> 395 * {String} userId: unique user identifier<br> 396 * {String} userRealName: user's name<br> 397 * {Date} editedDate: date dashboard was last edited<br> 398 * {Array} groups: groups dashboard is assigned to<br> 399 * {String} description: description of dashboard<br> 400 * {String} guid: uniqued dashboard identifier<br> 401 * {String} layoutConfig: Holds the various containers and panes on a dashboard and the widgets inside of the panes, including the widget states. 402 * This parameter provides an EXT JS style configuration used to layout the supported pane types in an OWF dashboard along. Each 403 * internal definition can hold nested panes in an items array, widgets in a widgets array, and default values for those widgets in a defaultValues array. 404 * Panes can have the following parameters:<br> 405 * <ul style="list-style-type:none"> 406 * <li>{String} xtype: container|accordionpane|desktoppane|fitpane|portalpane|tabbedpane|dashboardsplitter</li> 407 * <li>{Number} flex: 1 if for a pane; 3 for a container<li> 408 * <li>{String} htmlText: in pixels (e.g., 300px) or percent (e.g., 100%) or "variable"; valid if nested in a horizontally/vertically split pane</li> 409 * <li>{String} cls: left|right if nested in a horizontally split pane; top|bottom if nested in a vertically split pane; vbox|hbox if xtype is container</li> 410 * <li>{Array} items: an array of 2 nested pane configurations along with a possible dashboardspliiter for vbox and hbox containers; empty otherwise</li> 411 * <li>{String} paneType: accordionpane|desktoppane|fitpane|portalpane|tabbedpane; valid if xtype is not container</li> 412 * <li>{Array} layout: valid only for container xtype. Includes the following elements:</li> 413 * <ul style="list-style-type:none"> 414 * <li>{String} type: vbox|hbox</li> 415 * <li>{String} align: stretch</li> 416 * </ul> 417 * <li>{Array} widgets: array of widget state objects. Each has the following properties:</li> 418 * <ul style="list-style-type:none"> 419 * <li>{String} widgetGuid: unique widget identifier</li> 420 * <li>{Number} width: width of widget in pixels</li> 421 * <li>{Number} zIndex: in pixels</li> 422 * <li>{String} region: containing region on dashboard. Dashboard type specific.</li> 423 * <li>{Boolean} pinned: true if widget is pinned open</li> 424 * <li>{String} buttonId: identifier of button that opens widget</li> 425 * <li>{Number} height: height of widget in pixels</li> 426 * <li>{Number} columnPos: position of widget in a column</li> 427 * <li>{String} name: widget name</li> 428 * <li>{Number} statePosition</li> 429 * <li>{Boolean} active: true if this widget is the active (has focus) widget</li> 430 * <li>{String} uniqueId: unique widget identifier on dashboard</li> 431 * <li>{Boolean} minimized: true if widget is minimized</li> 432 * <li>{Boolean} buttonOpened: true if button launched widget is opened</li> 433 * <li>{Boolean} collapsed: true if widget is collapsed</li> 434 * <li>{Number} y: y-axis position in pixels</li> 435 * <li>{Number} x: x-axis position in pixels</li> 436 * <li>{Boolean} maximized: true if widget is maximized</li> 437 * </ul> 438 * <li>{String} defaultSettings: JSON string of default settings which varies by pane type; not valid for containers</li> 439 * </ul> 440 * <br> 441 * @param {Function} [cfg.onFailure] Callback to execute if there is an error (optional, a default alert provided). Callback parameter is an error string. 442 * @example 443 * 444 * var onSuccess = function(dashboard) { 445 * alert(dashboard.name); 446 * }; 447 * 448 * var onFailure = function(error) { 449 * alert(error); 450 * }; 451 * 452 * Ozone.pref.PrefServer.getDefaultDashboard({ 453 * onSuccess:onSuccess, 454 * onFailure:onFailure 455 * }); 456 */ 457 getDefaultDashboard : function (cfg){ 458 cfg.url = _url +"/dashboard?isdefault=true"; 459 cfg.method = "POST"; 460 Ozone.util.Transport.send(cfg); 461 }, 462 463 /** 464 * @description Sets the user's default dashboard 465 * @param {Object} cfg config object see below for properties 466 * @param {String} cfg.dashboardId Unigue dashbard identifier 467 * @param {Boolean} cfg.isDefault true to set as default dashboard 468 * @param {Function} cfg.onSuccess Callback function to capture the success result. Callback parameter is json representation of a Dashboard. 469 * This method will be passed the dashboard object which has the following properties:<br> 470 * <br> 471 * {Boolean} alteredByAdmin: true if altered by an administrator<br> 472 * {Date} createdDate: date dashboard was created<br> 473 * {Boolean} isGroupDashboard: true if dashboard is a group dashboard<br> 474 * {Boolean} isdefault: true if this is a default dashboard<br> 475 * {String} name: name of dashboard<br> 476 * {Object} user: the dashoard owner. Has the following properties:<br> 477 * {String} userId: unique user identifier<br> 478 * {Object} createdBy: dashboard creator. Has the following properties:<br> 479 * {String} userId: unique user identifier<br> 480 * {String} userRealName: user's name<br> 481 * {Date} editedDate: date dashboard was last edited<br> 482 * {Array} groups: groups dashboard is assigned to<br> 483 * {String} description: description of dashboard<br> 484 * {String} guid: uniqued dashboard identifier<br> 485 * {String} layoutConfig: Holds the various containers and panes on a dashboard and the widgets inside of the panes, including the widget states. 486 * This parameter provides an EXT JS style configuration used to layout the supported pane types in an OWF dashboard along. Each 487 * internal definition can hold nested panes in an items array, widgets in a widgets array, and default values for those widgets in a defaultValues array. 488 * Panes can have the following parameters:<br> 489 * <ul style="list-style-type:none"> 490 * <li>{String} xtype: container|accordionpane|desktoppane|fitpane|portalpane|tabbedpane|dashboardsplitter</li> 491 * <li>{Number} flex: 1 if for a pane; 3 for a container<li> 492 * <li>{String} htmlText: in pixels (e.g., 300px) or percent (e.g., 100%) or "variable"; valid if nested in a horizontally/vertically split pane</li> 493 * <li>{String} cls: left|right if nested in a horizontally split pane; top|bottom if nested in a vertically split pane; vbox|hbox if xtype is container</li> 494 * <li>{Array} items: an array of 2 nested pane configurations along with a possible dashboardspliiter for vbox and hbox containers; empty otherwise</li> 495 * <li>{String} paneType: accordionpane|desktoppane|fitpane|portalpane|tabbedpane; valid if xtype is not container</li> 496 * <li>{Array} layout: valid only for container xtype. Includes the following elements:</li> 497 * <ul style="list-style-type:none"> 498 * <li>{String} type: vbox|hbox</li> 499 * <li>{String} align: stretch</li> 500 * </ul> 501 * <li>{Array} widgets: array of widget state objects. Each has the following properties:</li> 502 * <ul style="list-style-type:none"> 503 * <li>{String} widgetGuid: unique widget identifier</li> 504 * <li>{Number} width: width of widget in pixels</li> 505 * <li>{Number} zIndex: in pixels</li> 506 * <li>{String} region: containing region on dashboard. Dashboard type specific.</li> 507 * <li>{Boolean} pinned: true if widget is pinned open</li> 508 * <li>{String} buttonId: identifier of button that opens widget</li> 509 * <li>{Number} height: height of widget in pixels</li> 510 * <li>{Number} columnPos: position of widget in a column</li> 511 * <li>{String} name: widget name</li> 512 * <li>{Number} statePosition</li> 513 * <li>{Boolean} active: true if this widget is the active (has focus) widget</li> 514 * <li>{String} uniqueId: unique widget identifier on dashboard</li> 515 * <li>{Boolean} minimized: true if widget is minimized</li> 516 * <li>{Boolean} buttonOpened: true if button launched widget is opened</li> 517 * <li>{Boolean} collapsed: true if widget is collapsed</li> 518 * <li>{Number} y: y-axis position in pixels</li> 519 * <li>{Number} x: x-axis position in pixels</li> 520 * <li>{Boolean} maximized: true if widget is maximized</li> 521 * </ul> 522 * <li>{String} defaultSettings: JSON string of default settings which varies by pane type; not valid for containers</li> 523 * </ul> 524 * <br> 525 * @param {Function} [cfg.onFailure] Callback to execute if there is an error (optional, a default alert provided). Callback parameter is an error string. 526 * @example 527 * 528 * var onSuccess = function(dashboard) { 529 * alert(dashboard.name); 530 * }; 531 * 532 * var onFailure = function(error) { 533 * alert(error); 534 * }; 535 * 536 * Ozone.pref.PrefServer.setDefaultDashboard({ 537 * dashboardId:'917b4cd0-ecbd-410b-afd9-42d150c26426', 538 * isDefault:true, 539 * onSuccess:onSuccess, 540 * onFailure:onFailure 541 * }); 542 */ 543 setDefaultDashboard : function (cfg){ 544 cfg.url = _url + "/dashboard/" + cfg.dashboardId + "?isdefault=" + cfg.isDefault; 545 cfg.method = 'PUT'; 546 setValue(cfg); 547 }, 548 549 /** 550 * @description Saves changes to a new or existing dashboard 551 * @param {Object} cfg config object see below for properties 552 * @param {Object} cfg.json The encoded JSON object representing the dashboard. 553 * The dashboard object has the following properties:<br> 554 * <br> 555 * {Boolean} alteredByAdmin: true if altered by an administrator<br> 556 * {Date} createdDate: date dashboard was created<br> 557 * {Boolean} isGroupDashboard: true if dashboard is a group dashboard<br> 558 * {String} layout: layout of dashboard<br> 559 * {Boolean} isdefault: true if this is a default dashboard<br> 560 * {String} name: name of dashboard<br> 561 * {Number} columnCount: number of columns if dashboard is a portal type<br> 562 * {Object} user: the dashoard owner. Has the following properties:<br> 563 * {String} userId: unique user identifier<br> 564 * {List} EDashboardLayoutList: list of dashboard types<br> 565 * {String} defaultSettings: JSON string of default settings which varies by dashboard type<br> 566 * {Object} createdBy: dashboard creator. Has the following properties:<br> 567 * {String} userId: unique user identifier<br> 568 * {String} userRealName: user's name<br> 569 * {Date} editedDate: date dashboard was last edited<br> 570 * {Array} groups: groups dashboard is assigned to<br> 571 * {String} description: description of dashboard<br> 572 * {String} guid: uniqued dashboard identifier<br> 573 * {String} layoutConfig: Holds the various containers and panes on a dashboard and the widgets inside of the panes, including the widget states. 574 * This parameter provides an EXT JS style configuration used to layout the supported pane types in an OWF dashboard along. Each 575 * internal definition can hold nested panes in an items array, widgets in a widgets array, and default values for those widgets in a defaultValues array. 576 * Panes can have the following parameters:<br> 577 * <ul style="list-style-type:none"> 578 * <li>{String} xtype: container|accordionpane|desktoppane|fitpane|portalpane|tabbedpane|dashboardsplitter</li> 579 * <li>{Number} flex: 1 if for a pane; 3 for a container<li> 580 * <li>{String} htmlText: in pixels (e.g., 300px) or percent (e.g., 100%) or "variable"; valid if nested in a horizontally/vertically split pane</li> 581 * <li>{String} cls: left|right if nested in a horizontally split pane; top|bottom if nested in a vertically split pane; vbox|hbox if xtype is container</li> 582 * <li>{Array} items: an array of 2 nested pane configurations along with a possible dashboardspliiter for vbox and hbox containers; empty otherwise</li> 583 * <li>{String} paneType: accordionpane|desktoppane|fitpane|portalpane|tabbedpane; valid if xtype is not container</li> 584 * <li>{Array} layout: valid only for container xtype. Includes the following elements:</li> 585 * <ul style="list-style-type:none"> 586 * <li>{String} type: vbox|hbox</li> 587 * <li>{String} align: stretch</li> 588 * </ul> 589 * <li>{Array} widgets: array of widget state objects. Each has the following properties:</li> 590 * <ul style="list-style-type:none"> 591 * <li>{String} widgetGuid: unique widget identifier</li> 592 * <li>{Number} width: width of widget in pixels</li> 593 * <li>{Number} zIndex: in pixels</li> 594 * <li>{String} region: containing region on dashboard. Dashboard type specific.</li> 595 * <li>{Boolean} pinned: true if widget is pinned open</li> 596 * <li>{String} buttonId: identifier of button that opens widget</li> 597 * <li>{Number} height: height of widget in pixels</li> 598 * <li>{Number} columnPos: position of widget in a column</li> 599 * <li>{String} name: widget name</li> 600 * <li>{Number} statePosition</li> 601 * <li>{Boolean} active: true if this widget is the active (has focus) widget</li> 602 * <li>{String} uniqueId: unique widget identifier on dashboard</li> 603 * <li>{Boolean} minimized: true if widget is minimized</li> 604 * <li>{Boolean} buttonOpened: true if button launched widget is opened</li> 605 * <li>{Boolean} collapsed: true if widget is collapsed</li> 606 * <li>{Number} y: y-axis position in pixels</li> 607 * <li>{Number} x: x-axis position in pixels</li> 608 * <li>{Boolean} maximized: true if widget is maximized</li> 609 * </ul> 610 * <li>{String} defaultSettings: JSON string of default settings which varies by pane type; not valid for containers</li> 611 * </ul> 612 * <br> 613 * @param {Boolean} cfg.saveAsNew A Boolean indicating whether the entity being saved is new. 614 * @param {Function} cfg.onSuccess Callback function to capture the success result. Callback parameter is json representation of a Dashboard. 615 * This method will be passed the dashboard object which has the following properties:<br> 616 * <br> 617 * {Boolean} alteredByAdmin: true if altered by an administrator<br> 618 * {Date} createdDate: date dashboard was created<br> 619 * {Boolean} isGroupDashboard: true if dashboard is a group dashboard<br> 620 * {Boolean} isdefault: true if this is a default dashboard<br> 621 * {String} name: name of dashboard<br> 622 * {Object} user: the dashoard owner. Has the following properties:<br> 623 * {String} userId: unique user identifier<br> 624 * {Object} createdBy: dashboard creator. Has the following properties:<br> 625 * {String} userId: unique user identifier<br> 626 * {String} userRealName: user's name<br> 627 * {Date} editedDate: date dashboard was last edited<br> 628 * {Array} groups: groups dashboard is assigned to<br> 629 * {String} description: description of dashboard<br> 630 * {String} guid: uniqued dashboard identifier<br> 631 * {String} layoutConfig: Holds the various containers and panes on a dashboard and the widgets inside of the panes, including the widget states. 632 * This parameter provides an EXT JS style configuration used to layout the supported pane types in an OWF dashboard along. Each 633 * internal definition can hold nested panes in an items array, widgets in a widgets array, and default values for those widgets in a defaultValues array. 634 * Panes can have the following parameters:<br> 635 * <ul style="list-style-type:none"> 636 * <li>{String} xtype: container|accordionpane|desktoppane|fitpane|portalpane|tabbedpane|dashboardsplitter</li> 637 * <li>{Number} flex: 1 if for a pane; 3 for a container<li> 638 * <li>{String} htmlText: in pixels (e.g., 300px) or percent (e.g., 100%) or "variable"; valid if nested in a horizontally/vertically split pane</li> 639 * <li>{String} cls: left|right if nested in a horizontally split pane; top|bottom if nested in a vertically split pane; vbox|hbox if xtype is container</li> 640 * <li>{Array} items: an array of 2 nested pane configurations along with a possible dashboardspliiter for vbox and hbox containers; empty otherwise</li> 641 * <li>{String} paneType: accordionpane|desktoppane|fitpane|portalpane|tabbedpane; valid if xtype is not container</li> 642 * <li>{Array} layout: valid only for container xtype. Includes the following elements:</li> 643 * <ul style="list-style-type:none"> 644 * <li>{String} type: vbox|hbox</li> 645 * <li>{String} align: stretch</li> 646 * </ul> 647 * <li>{Array} widgets: array of widget state objects. Each has the following properties:</li> 648 * <ul style="list-style-type:none"> 649 * <li>{String} widgetGuid: unique widget identifier</li> 650 * <li>{Number} width: width of widget in pixels</li> 651 * <li>{Number} zIndex: in pixels</li> 652 * <li>{String} region: containing region on dashboard. Dashboard type specific.</li> 653 * <li>{Boolean} pinned: true if widget is pinned open</li> 654 * <li>{String} buttonId: identifier of button that opens widget</li> 655 * <li>{Number} height: height of widget in pixels</li> 656 * <li>{Number} columnPos: position of widget in a column</li> 657 * <li>{String} name: widget name</li> 658 * <li>{Number} statePosition</li> 659 * <li>{Boolean} active: true if this widget is the active (has focus) widget</li> 660 * <li>{String} uniqueId: unique widget identifier on dashboard</li> 661 * <li>{Boolean} minimized: true if widget is minimized</li> 662 * <li>{Boolean} buttonOpened: true if button launched widget is opened</li> 663 * <li>{Boolean} collapsed: true if widget is collapsed</li> 664 * <li>{Number} y: y-axis position in pixels</li> 665 * <li>{Number} x: x-axis position in pixels</li> 666 * <li>{Boolean} maximized: true if widget is maximized</li> 667 * </ul> 668 * <li>{String} defaultSettings: JSON string of default settings which varies by pane type; not valid for containers</li> 669 * </ul> 670 * <br> 671 * @param {Function} [cfg.onFailure] Callback to execute if there is an error (optional, a default alert provided). Callback parameter is an error string. 672 * @param {Boolean} [cfg.async] Async true or false defaults to true 673 * @example 674 * 675 * var onSuccess = function(dashboard) { 676 * alert(dashboard.name); 677 * }; 678 * 679 * var onFailure = function(error) { 680 * alert(error); 681 * }; 682 * 683 * var dashboard = { 684 * alteredByAdmin: 'false', 685 * createdDate: '04/18/2012 11:29 AM EDT', 686 * isGroupDashboard: false, 687 * isdefault: false, 688 * locked: false, 689 * name: 'My Dashboard', 690 * user: { 691 * userId: 'testAdmin1', 692 * }, 693 * createdBy: { 694 * userId: 'testAdmin1', 695 * userRealName: 'Test Admin 1' 696 * }, 697 * editedDate: '04/18/2012 11:29 AM EDT', 698 * groups: [], 699 * description: 'This is my dashboard', 700 * guid: guid.util.guid(), 701 * layoutConfig: { 702 * xtype: "desktoppane", 703 * flex: 1, 704 * height: "100%", 705 * items: [ 706 * ], 707 * paneType: "desktoppane", 708 * widgets: [{ 709 * widgetGuid: "ec5435cf-4021-4f2a-ba69-dde451d12551", 710 * uniqueId: guid.util.guid(), 711 * dashboardGuid: "6d7219cb-b485-ace5-946b-0affa1f227a3", 712 * paneGuid: guid.util.guid(), 713 * name: "Channel Listener", 714 * active: false, 715 * x: 50, 716 * y: 66, 717 * minimized: false, 718 * maximized: false, 719 * pinned: false, 720 * collapsed: false, 721 * columnPos: 0, 722 * buttonId: null, 723 * buttonOpened: false, 724 * region: "none", 725 * statePosition: 1, 726 * intentConfig: null, 727 * singleton: false, 728 * floatingWidget: false, 729 * background: false, 730 * zIndex: 19050, 731 * height: 440, 732 * width: 540 733 * } 734 * ], 735 * defaultSettings: { 736 * widgetStates: { 737 * "ec5435cf-4021-4f2a-ba69-dde451d12551": { 738 * x: 50, 739 * y: 66, 740 * height: 440, 741 * width: 540, 742 * timestamp: 1349809747336 743 * } 744 * } 745 * } 746 * } 747 * }; 748 * 749 * Ozone.pref.PrefServer.createOrUpdateDashboard({ 750 * json: dashboard, 751 * saveAsNew: true, 752 * onSuccess: onSuccess, 753 * onFailure: onFailure, 754 * async: true 755 * }); 756 */ 757 createOrUpdateDashboard : function (cfg){ 758 cfg.url = _url + "/" + 'dashboard' + "/" + cfg.json.guid; 759 var postParams = generateDashboardPostParamsJSON(cfg.json); 760 postParams.bypassLayoutRearrange = true; 761 cfg.method = cfg.saveAsNew ? 'POST' : 'PUT'; 762 cfg.jsonObject = postParams; 763 setValuesViaJSONObject(cfg); 764 }, 765 766 /** 767 * @description Copies an existing dashboard and saves it as new 768 * @param {Object} cfg config object see below for properties 769 * @param {Object} cfg.json The encoded JSON object representing the dashboard. 770 * The dashboard object has the following properties:<br> 771 * <br> 772 * {Boolean} alteredByAdmin: true if altered by an administrator<br> 773 * {Date} createdDate: date dashboard was created<br> 774 * {Boolean} isGroupDashboard: true if dashboard is a group dashboard<br> 775 * {Boolean} isdefault: true if this is a default dashboard<br> 776 * {String} name: name of dashboard<br> 777 * {Object} user: the dashoard owner. Has the following properties:<br> 778 * {String} userId: unique user identifier<br> 779 * {Object} createdBy: dashboard creator. Has the following properties:<br> 780 * {String} userId: unique user identifier<br> 781 * {String} userRealName: user's name<br> 782 * {Date} editedDate: date dashboard was last edited<br> 783 * {Array} groups: groups dashboard is assigned to<br> 784 * {String} description: description of dashboard<br> 785 * {String} guid: uniqued dashboard identifier<br> 786 * {String} layoutConfig: Holds the various containers and panes on a dashboard and the widgets inside of the panes, including the widget states. 787 * This parameter provides an EXT JS style configuration used to layout the supported pane types in an OWF dashboard along. Each 788 * internal definition can hold nested panes in an items array, widgets in a widgets array, and default values for those widgets in a defaultValues array. 789 * Panes can have the following parameters:<br> 790 * <ul style="list-style-type:none"> 791 * <li>{String} xtype: container|accordionpane|desktoppane|fitpane|portalpane|tabbedpane|dashboardsplitter</li> 792 * <li>{Number} flex: 1 if for a pane; 3 for a container<li> 793 * <li>{String} htmlText: in pixels (e.g., 300px) or percent (e.g., 100%) or "variable"; valid if nested in a horizontally/vertically split pane</li> 794 * <li>{String} cls: left|right if nested in a horizontally split pane; top|bottom if nested in a vertically split pane; vbox|hbox if xtype is container</li> 795 * <li>{Array} items: an array of 2 nested pane configurations along with a possible dashboardspliiter for vbox and hbox containers; empty otherwise</li> 796 * <li>{String} paneType: accordionpane|desktoppane|fitpane|portalpane|tabbedpane; valid if xtype is not container</li> 797 * <li>{Array} layout: valid only for container xtype. Includes the following elements:</li> 798 * <ul style="list-style-type:none"> 799 * <li>{String} type: vbox|hbox</li> 800 * <li>{String} align: stretch</li> 801 * </ul> 802 * <li>{Array} widgets: array of widget state objects. Each has the following properties:</li> 803 * <ul style="list-style-type:none"> 804 * <li>{String} widgetGuid: unique widget identifier</li> 805 * <li>{Number} width: width of widget in pixels</li> 806 * <li>{Number} zIndex: in pixels</li> 807 * <li>{String} region: containing region on dashboard. Dashboard type specific.</li> 808 * <li>{Boolean} pinned: true if widget is pinned open</li> 809 * <li>{String} buttonId: identifier of button that opens widget</li> 810 * <li>{Number} height: height of widget in pixels</li> 811 * <li>{Number} columnPos: position of widget in a column</li> 812 * <li>{String} name: widget name</li> 813 * <li>{Number} statePosition</li> 814 * <li>{Boolean} active: true if this widget is the active (has focus) widget</li> 815 * <li>{String} uniqueId: unique widget identifier on dashboard</li> 816 * <li>{Boolean} minimized: true if widget is minimized</li> 817 * <li>{Boolean} buttonOpened: true if button launched widget is opened</li> 818 * <li>{Boolean} collapsed: true if widget is collapsed</li> 819 * <li>{Number} y: y-axis position in pixels</li> 820 * <li>{Number} x: x-axis position in pixels</li> 821 * <li>{Boolean} maximized: true if widget is maximized</li> 822 * </ul> 823 * <li>{String} defaultSettings: JSON string of default settings which varies by pane type; not valid for containers</li> 824 * </ul> 825 * <br> 826 * @param {Function} cfg.onSuccess Callback function to capture the success result. Callback parameter is json representation of a Dashboard. 827 * This method will be passed the dashboard object which has the following properties:<br> 828 * <br> 829 * {Boolean} alteredByAdmin: true if altered by an administrator<br> 830 * {Date} createdDate: date dashboard was created<br> 831 * {Boolean} isGroupDashboard: true if dashboard is a group dashboard<br> 832 * {Boolean} isdefault: true if this is a default dashboard<br> 833 * {String} name: name of dashboard<br> 834 * {Object} user: the dashoard owner. Has the following properties:<br> 835 * {String} userId: unique user identifier<br> 836 * {Object} createdBy: dashboard creator. Has the following properties:<br> 837 * {String} userId: unique user identifier<br> 838 * {String} userRealName: user's name<br> 839 * {Date} editedDate: date dashboard was last edited<br> 840 * {Array} groups: groups dashboard is assigned to<br> 841 * {String} description: description of dashboard<br> 842 * {String} guid: uniqued dashboard identifier<br> 843 * {String} layoutConfig: Holds the various containers and panes on a dashboard and the widgets inside of the panes, including the widget states. 844 * This parameter provides an EXT JS style configuration used to layout the supported pane types in an OWF dashboard along. Each 845 * internal definition can hold nested panes in an items array, widgets in a widgets array, and default values for those widgets in a defaultValues array. 846 * Panes can have the following parameters:<br> 847 * <ul style="list-style-type:none"> 848 * <li>{String} xtype: container|accordionpane|desktoppane|fitpane|portalpane|tabbedpane|dashboardsplitter</li> 849 * <li>{Number} flex: 1 if for a pane; 3 for a container<li> 850 * <li>{String} htmlText: in pixels (e.g., 300px) or percent (e.g., 100%) or "variable"; valid if nested in a horizontally/vertically split pane</li> 851 * <li>{String} cls: left|right if nested in a horizontally split pane; top|bottom if nested in a vertically split pane; vbox|hbox if xtype is container</li> 852 * <li>{Array} items: an array of 2 nested pane configurations along with a possible dashboardspliiter for vbox and hbox containers; empty otherwise</li> 853 * <li>{String} paneType: accordionpane|desktoppane|fitpane|portalpane|tabbedpane; valid if xtype is not container</li> 854 * <li>{Array} layout: valid only for container xtype. Includes the following elements:</li> 855 * <ul style="list-style-type:none"> 856 * <li>{String} type: vbox|hbox</li> 857 * <li>{String} align: stretch</li> 858 * </ul> 859 * <li>{Array} widgets: array of widget state objects. Each has the following properties:</li> 860 * <ul style="list-style-type:none"> 861 * <li>{String} widgetGuid: unique widget identifier</li> 862 * <li>{Number} width: width of widget in pixels</li> 863 * <li>{Number} zIndex: in pixels</li> 864 * <li>{String} region: containing region on dashboard. Dashboard type specific.</li> 865 * <li>{Boolean} pinned: true if widget is pinned open</li> 866 * <li>{String} buttonId: identifier of button that opens widget</li> 867 * <li>{Number} height: height of widget in pixels</li> 868 * <li>{Number} columnPos: position of widget in a column</li> 869 * <li>{String} name: widget name</li> 870 * <li>{Number} statePosition</li> 871 * <li>{Boolean} active: true if this widget is the active (has focus) widget</li> 872 * <li>{String} uniqueId: unique widget identifier on dashboard</li> 873 * <li>{Boolean} minimized: true if widget is minimized</li> 874 * <li>{Boolean} buttonOpened: true if button launched widget is opened</li> 875 * <li>{Boolean} collapsed: true if widget is collapsed</li> 876 * <li>{Number} y: y-axis position in pixels</li> 877 * <li>{Number} x: x-axis position in pixels</li> 878 * <li>{Boolean} maximized: true if widget is maximized</li> 879 * </ul> 880 * <li>{String} defaultSettings: JSON string of default settings which varies by pane type; not valid for containers</li> 881 * </ul> 882 * <br> 883 * @param {Function} [cfg.onFailure] Callback to execute if there is an error (optional, a default alert provided). Callback parameter is an error string. 884 * @example 885 * 886 * var onSuccess = function(dashboard) { 887 * alert(dashboard.name); 888 * }; 889 * 890 * var onFailure = function(error) { 891 * alert(error); 892 * }; 893 * 894 * var dashboard = { 895 * alteredByAdmin: 'false', 896 * createdDate: '04/18/2012 11:29 AM EDT', 897 * isGroupDashboard: false, 898 * isdefault: false, 899 * name: 'My Dashboard', 900 * user: { 901 * userId: 'testAdmin1', 902 * }, 903 * createdBy: { 904 * userId: 'testAdmin1', 905 * userRealName: 'Test Admin 1' 906 * }, 907 * editedDate: '04/18/2012 11:29 AM EDT', 908 * groups: [], 909 * description: 'This is my dashboard', 910 * guid: guid.util.guid(), 911 * }; 912 * 913 * Ozone.pref.PrefServer.cloneDashboard({ 914 * json: dashboard, 915 * onSuccess: onSuccess, 916 * onFailure: onFailure 917 * }); 918 */ 919 cloneDashboard : function (cfg){ 920 cfg.url = _url + "/" + 'dashboard' + "/" + cfg.json.guid; 921 var postParams = generateDashboardPostParamsJSON(cfg.json); 922 postParams.cloned = true; 923 cfg.method = 'POST'; 924 cfg.jsonObject = postParams; 925 setValuesViaJSONObject(cfg); 926 }, 927 928 /** 929 * @description Saves changes to existing dashboards 930 * @param {Object} cfg config object see below for properties 931 * @param {Array} cfg.viewsToUpdate array of JSON objects containing the view guid and data to be updated 932 * @param {Array} cfg.viewGuidsToDelete array of guids of views to be deleted 933 * @param {Boolean} cfg.updateOrder flag to update order 934 * @param {Function} cfg.onSuccess callback function to capture the success result 935 * @param {Function} [cfg.onFailure] callback to execute if there is an error (optional, a default alert provided) 936 */ 937 updateAndDeleteDashboards : function (cfg){ 938 cfg.url = _url + "/dashboard"; 939 var postParams = { 940 '_method': 'PUT', 941 'viewsToUpdate': Ozone.util.toString(cfg.viewsToUpdate), 942 'viewGuidsToDelete': Ozone.util.toString(cfg.viewGuidsToDelete), 943 'updateOrder': cfg.updateOrder 944 }; 945 946 cfg.method = 'POST'; 947 cfg.content = postParams; 948 Ozone.util.Transport.send(cfg); 949 }, 950 951 /** 952 * @description Deletes the dashboard with the specified id 953 * @param {Object} cfg config object see below for properties 954 * @param {String} cfg.dashboardId Unigue dashbard identifier 955 * @param {Function} cfg.onSuccess Callback function to capture the success result. Callback parameter is json representation of a Dashboard. 956 * This method will be passed the dashboard object which has the following properties:<br> 957 * <br> 958 * {Boolean} alteredByAdmin: true if altered by an administrator<br> 959 * {Date} createdDate: date dashboard was created<br> 960 * {Boolean} isGroupDashboard: true if dashboard is a group dashboard<br> 961 * {Boolean} isdefault: true if this is a default dashboard<br> 962 * {String} name: name of dashboard<br> 963 * {Object} user: the dashoard owner. Has the following properties:<br> 964 * {String} userId: unique user identifier<br> 965 * {Object} createdBy: dashboard creator. Has the following properties:<br> 966 * {String} userId: unique user identifier<br> 967 * {String} userRealName: user's name<br> 968 * {Date} editedDate: date dashboard was last edited<br> 969 * {Array} groups: groups dashboard is assigned to<br> 970 * {String} description: description of dashboard<br> 971 * {String} guid: uniqued dashboard identifier<br> 972 * {String} layoutConfig: Holds the various containers and panes on a dashboard and the widgets inside of the panes, including the widget states. 973 * This parameter provides an EXT JS style configuration used to layout the supported pane types in an OWF dashboard along. Each 974 * internal definition can hold nested panes in an items array, widgets in a widgets array, and default values for those widgets in a defaultValues array. 975 * Panes can have the following parameters:<br> 976 * <ul style="list-style-type:none"> 977 * <li>{String} xtype: container|accordionpane|desktoppane|fitpane|portalpane|tabbedpane|dashboardsplitter</li> 978 * <li>{Number} flex: 1 if for a pane; 3 for a container<li> 979 * <li>{String} htmlText: in pixels (e.g., 300px) or percent (e.g., 100%) or "variable"; valid if nested in a horizontally/vertically split pane</li> 980 * <li>{String} cls: left|right if nested in a horizontally split pane; top|bottom if nested in a vertically split pane; vbox|hbox if xtype is container</li> 981 * <li>{Array} items: an array of 2 nested pane configurations along with a possible dashboardspliiter for vbox and hbox containers; empty otherwise</li> 982 * <li>{String} paneType: accordionpane|desktoppane|fitpane|portalpane|tabbedpane; valid if xtype is not container</li> 983 * <li>{Array} layout: valid only for container xtype. Includes the following elements:</li> 984 * <ul style="list-style-type:none"> 985 * <li>{String} type: vbox|hbox</li> 986 * <li>{String} align: stretch</li> 987 * </ul> 988 * <li>{Array} widgets: array of widget state objects. Each has the following properties:</li> 989 * <ul style="list-style-type:none"> 990 * <li>{String} widgetGuid: unique widget identifier</li> 991 * <li>{Number} width: width of widget in pixels</li> 992 * <li>{Number} zIndex: in pixels</li> 993 * <li>{String} region: containing region on dashboard. Dashboard type specific.</li> 994 * <li>{Boolean} pinned: true if widget is pinned open</li> 995 * <li>{String} buttonId: identifier of button that opens widget</li> 996 * <li>{Number} height: height of widget in pixels</li> 997 * <li>{Number} columnPos: position of widget in a column</li> 998 * <li>{String} name: widget name</li> 999 * <li>{Number} statePosition</li> 1000 * <li>{Boolean} active: true if this widget is the active (has focus) widget</li> 1001 * <li>{String} uniqueId: unique widget identifier on dashboard</li> 1002 * <li>{Boolean} minimized: true if widget is minimized</li> 1003 * <li>{Boolean} buttonOpened: true if button launched widget is opened</li> 1004 * <li>{Boolean} collapsed: true if widget is collapsed</li> 1005 * <li>{Number} y: y-axis position in pixels</li> 1006 * <li>{Number} x: x-axis position in pixels</li> 1007 * <li>{Boolean} maximized: true if widget is maximized</li> 1008 * </ul> 1009 * <li>{String} defaultSettings: JSON string of default settings which varies by pane type; not valid for containers</li> 1010 * </ul> 1011 * <br> 1012 * @param {Function} [cfg.onFailure] Callback to execute if there is an error (optional, a default alert provided). Callback parameter is an error string. 1013 * @example 1014 * 1015 * var onSuccess = function(dashboard) { 1016 * alert(dashboard.name); 1017 * }; 1018 * 1019 * var onFailure = function(error) { 1020 * alert(error); 1021 * }; 1022 * 1023 * Ozone.pref.PrefServer.deleteDashboard({ 1024 * dashboardId:'917b4cd0-ecbd-410b-afd9-42d150c26426', 1025 * onSuccess:onSuccess, 1026 * onFailure:onFailure 1027 * }); 1028 */ 1029 deleteDashboard : function (cfg){ 1030 cfg.url = _url + "/dashboard/" + cfg.dashboardId; 1031 deleteBase(cfg); 1032 }, 1033 1034 /** 1035 * @description Returns all dashboards for the logged in user. 1036 * @param {Object} cfg config object see below for properties 1037 * @param {Function} cfg.onSuccess Callback function to capture the success result. 1038 * This method is passed an object having the following properties:<br> 1039 * <br> 1040 * {Boolean} success: true if dashboards found<br> 1041 * {Number} results: number of dashboards found<br> 1042 * {Array} data: array of dashboards objects found. Dashboard object has the following properties:<br> 1043 * <br> 1044 * {Boolean} alteredByAdmin: true if altered by an administrator<br> 1045 * {Date} createdDate: date dashboard was created<br> 1046 * {Boolean} isGroupDashboard: true if dashboard is a group dashboard<br> 1047 * {Boolean} isdefault: true if this is a default dashboard<br> 1048 * {String} name: name of dashboard<br> 1049 * {Object} user: the dashoard owner. Has the following properties:<br> 1050 * {String} userId: unique user identifier<br> 1051 * {Object} createdBy: dashboard creator. Has the following properties:<br> 1052 * {String} userId: unique user identifier<br> 1053 * {String} userRealName: user's name<br> 1054 * {Date} editedDate: date dashboard was last edited<br> 1055 * {Array} groups: groups dashboard is assigned to<br> 1056 * {String} description: description of dashboard<br> 1057 * {String} guid: uniqued dashboard identifier<br> 1058 * {String} layoutConfig: Holds the various containers and panes on a dashboard and the widgets inside of the panes, including the widget states. 1059 * This parameter provides an EXT JS style configuration used to layout the supported pane types in an OWF dashboard along. Each 1060 * internal definition can hold nested panes in an items array, widgets in a widgets array, and default values for those widgets in a defaultValues array. 1061 * Panes can have the following parameters:<br> 1062 * <ul style="list-style-type:none"> 1063 * <li>{String} xtype: container|accordionpane|desktoppane|fitpane|portalpane|tabbedpane|dashboardsplitter</li> 1064 * <li>{Number} flex: 1 if for a pane; 3 for a container<li> 1065 * <li>{String} htmlText: in pixels (e.g., 300px) or percent (e.g., 100%) or "variable"; valid if nested in a horizontally/vertically split pane</li> 1066 * <li>{String} cls: left|right if nested in a horizontally split pane; top|bottom if nested in a vertically split pane; vbox|hbox if xtype is container</li> 1067 * <li>{Array} items: an array of 2 nested pane configurations along with a possible dashboardspliiter for vbox and hbox containers; empty otherwise</li> 1068 * <li>{String} paneType: accordionpane|desktoppane|fitpane|portalpane|tabbedpane; valid if xtype is not container</li> 1069 * <li>{Array} layout: valid only for container xtype. Includes the following elements:</li> 1070 * <ul style="list-style-type:none"> 1071 * <li>{String} type: vbox|hbox</li> 1072 * <li>{String} align: stretch</li> 1073 * </ul> 1074 * <li>{Array} widgets: array of widget state objects. Each has the following properties:</li> 1075 * <ul style="list-style-type:none"> 1076 * <li>{String} widgetGuid: unique widget identifier</li> 1077 * <li>{Number} width: width of widget in pixels</li> 1078 * <li>{Number} zIndex: in pixels</li> 1079 * <li>{String} region: containing region on dashboard. Dashboard type specific.</li> 1080 * <li>{Boolean} pinned: true if widget is pinned open</li> 1081 * <li>{String} buttonId: identifier of button that opens widget</li> 1082 * <li>{Number} height: height of widget in pixels</li> 1083 * <li>{Number} columnPos: position of widget in a column</li> 1084 * <li>{String} name: widget name</li> 1085 * <li>{Number} statePosition</li> 1086 * <li>{Boolean} active: true if this widget is the active (has focus) widget</li> 1087 * <li>{String} uniqueId: unique widget identifier on dashboard</li> 1088 * <li>{Boolean} minimized: true if widget is minimized</li> 1089 * <li>{Boolean} buttonOpened: true if button launched widget is opened</li> 1090 * <li>{Boolean} collapsed: true if widget is collapsed</li> 1091 * <li>{Number} y: y-axis position in pixels</li> 1092 * <li>{Number} x: x-axis position in pixels</li> 1093 * <li>{Boolean} maximized: true if widget is maximized</li> 1094 * </ul> 1095 * <li>{String} defaultSettings: JSON string of default settings which varies by pane type; not valid for containers</li> 1096 * </ul> 1097 * <br> 1098 * <br> 1099 * @param {Function} [cfg.onFailure] Callback to execute if there is an error (optional, a default alert provided). Callback parameter is an error string. 1100 * @example 1101 * 1102 * var onSuccess = function(obj) { 1103 * alert(obj.results); 1104 * if (obj.results > 0) { 1105 * for (var i = 0; i < obj.results; i++) { 1106 * alert(obj.data[i].name); 1107 * } 1108 * } 1109 * }; 1110 * 1111 * var onFailure = function(error) { 1112 * alert(error); 1113 * }; 1114 * 1115 * Ozone.pref.PrefServer.findDashboards({ 1116 * onSuccess:onSuccess, 1117 * onFailure:onFailure 1118 * }); 1119 */ 1120 findDashboards : function (cfg){ 1121 cfg.url = "dashboard"; 1122 list(cfg); 1123 }, 1124 1125 /** 1126 * @deprecated Deprecated starting with OWF 7. Dashboards no longer have a specific type. This function is stubbed 1127 * to return success with 0 results until removal. 1128 * @description Returns all dashboards for the logged in user filtered by the type of dashboard. 1129 * @param {Object} cfg config object see below for properties 1130 * @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. 1131 * @param {Function} cfg.onSuccess Callback function to capture the success result. 1132 * This method is passed an object having the following properties:<br> 1133 * <br> 1134 * {Boolean} success: true if dashboards found<br> 1135 * {Number} results: number of dashboards found<br> 1136 * {Array} data: an empty array<br> 1137 * 1138 * <br> 1139 * @param {Function} [cfg.onFailure] Callback to execute if there is an error (optional, a default alert provided). Callback parameter is an error string. 1140 * @example 1141 * 1142 * var onSuccess = function(obj) { 1143 * alert(obj.results); 1144 * if (obj.results > 0) { 1145 * for (var i = 0; i < obj.results; i++) { 1146 * alert(obj.data[i].name); 1147 * } 1148 * } 1149 * }; 1150 * 1151 * var onFailure = function(error) { 1152 * alert(error); 1153 * }; 1154 * 1155 * Ozone.pref.PrefServer.findDashboardsByType({ 1156 * type:'desktop', 1157 * onSuccess:onSuccess, 1158 * onFailure:onFailure 1159 * }); 1160 */ 1161 findDashboardsByType : function (cfg){ 1162 if (typeof cfg.onSuccess === 'function') { 1163 var retVal = { 1164 data: [], 1165 results: 0, 1166 success: true 1167 }; 1168 cfg.onSuccess(retVal); 1169 } 1170 }, 1171 1172 /** 1173 * @description Gets the widget with the specified id 1174 * @param {Object} cfg config object see below for properties 1175 * @param {String} cfg.widgetId The guid of the widget. 1176 * @param {String} cfg.universalName The universal name for the widget. 1177 * @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} 1178 * This method is passed an object having the following properties:<br> 1179 * <br> 1180 * {Number} id: database pk identifier<br> 1181 * {String} namespace: "widget"<br> 1182 * {Object} value: widget object having the following properties:<br> 1183 * <br> 1184 * {Boolean} editable: true if widget can be edited<br> 1185 * {Boolean} visible: true if widget is visible<br> 1186 * {Number} position<br> 1187 * {String} userId: widget owner identifier<br> 1188 * {String} userRealName: widget owner name<br> 1189 * {String} namespace: widget name<br> 1190 * {String} url: url of widget application<br> 1191 * {String} headerIcon: url of widget header icon<br> 1192 * {String} image: url of widget image<br> 1193 * {String} smallIconUrl: url of widget's small icon<br> 1194 * {String} largeIconUrl: url of widget's large icon<br> 1195 * {Number} width: width of the widget in pixels<br> 1196 * {Number} height: height of the widget in pixels<br> 1197 * {Number} x: x-axis position<br> 1198 * {Number} y: y-axis position<br> 1199 * {Boolean} minimized: true if widget is minimized<br> 1200 * {Boolean} maximized: true if widget is maximized<br> 1201 * {String} widgetVersion: widget version<br> 1202 * {Array} tags: array of tag strings<br> 1203 * {Boolean} definitionVisible: true if definition is visible<br> 1204 * {Boolean} singleton: true if widget is a singleton<br> 1205 * {Boolean} background: true if widget runs in the background<br> 1206 * {Array} allRequired: array of all widgets required by this widget<br> 1207 * {Array} directRequired: array of all widgets directly required by this widget<br> 1208 * {Array} widgetTypes: array of widget types this widget belongs to<br> 1209 * <br> 1210 * {String} path: The guid of the widget.<br> 1211 * <br> 1212 * @param {Function} [cfg.onFailure] Callback to execute if there is an error (optional, a default alert provided). Callback parameter is an error string. 1213 * @example 1214 * 1215 * var onSuccess = function(obj) { 1216 * if (obj.value) { 1217 * alert(obj.value.namespace); 1218 * } 1219 * }; 1220 * 1221 * var onFailure = function(error) { 1222 * alert(error); 1223 * }; 1224 * 1225 * Ozone.pref.PrefServer.getWidget({ 1226 * widgetId:'ea5435cf-4021-4f2a-ba69-dde451d12551', 1227 * widgetUuid: 'com.company.widget.name', 1228 * onSuccess:onSuccess, 1229 * onFailure:onFailure 1230 * }); 1231 */ 1232 getWidget : function (cfg){ 1233 cfg.url = _url + "/" + 'widget' + "/" + cfg.widgetId; 1234 if(cfg.universalName) { 1235 cfg.url += '?universalName=' + cfg.universalName; 1236 } 1237 get(cfg); 1238 }, 1239 1240 /** 1241 * @description Gets all widgets for a given user. 1242 * @param {Object} cfg config object see below for properties 1243 * @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) 1244 * @param {Object} [cfg.searchParams] object containing search parameters 1245 * @param {String} [cfg.searchParams.widgetName] name of widget '%' are wildcards 1246 * @param {String} [cfg.searchParams.widgetNameExactMatch] true or false to match the name exactly. defaults to false 1247 * @param {String} [cfg.searchParams.widgetVersion] version of widget '%' are wildcards 1248 * @param {String} [cfg.searchParams.widgetGuid] Guid of widget '%' are wildcards 1249 * @param {String} [cfg.searchParams.universalName] Universal name of widget '%' are wildcards 1250 * @param {Function} cfg.onSuccess callback function to capture the success result. 1251 * This method is passed an array of objects having the following properties:<br> 1252 * <br> 1253 * {Number} id: database pk identifier<br> 1254 * {String} namespace: "widget"<br> 1255 * {Object} value: widget object having the following properties:<br> 1256 * <br> 1257 * {Boolean} editable: true if widget can be edited<br> 1258 * {Boolean} visible: true if widget is visible<br> 1259 * {Number} position<br> 1260 * {String} userId: widget owner identifier<br> 1261 * {String} userRealName: widget owner name<br> 1262 * {String} namespace: widget name<br> 1263 * {String} url: url of widget application<br> 1264 * {String} headerIcon: url of widget header icon<br> 1265 * {String} image: url of widget image<br> 1266 * {String} smallIconUrl: url of widget's small icon<br> 1267 * {String} largeIconUrl: url of widget's large icon<br> 1268 * {Number} width: width of the widget in pixels<br> 1269 * {Number} height: height of the widget in pixels<br> 1270 * {Number} x: x-axis position<br> 1271 * {Number} y: y-axis position<br> 1272 * {Boolean} minimized: true if widget is minimized<br> 1273 * {Boolean} maximized: true if widget is maximized<br> 1274 * {String} widgetVersion: widget version<br> 1275 * {Array} tags: array of tag strings<br> 1276 * {Boolean} definitionVisible: true if definition is visible<br> 1277 * {Boolean} singleton: true if widget is a singleton<br> 1278 * {Boolean} background: true if widget runs in the background<br> 1279 * {Array} allRequired: array of all widgets required by this widget<br> 1280 * {Array} directRequired: array of all widgets directly required by this widget<br> 1281 * {Array} widgetTypes: array of widget types this widget belongs to<br> 1282 * <br> 1283 * {String} path: The guid of the widget.<br> 1284 * <br> 1285 * @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 1286 * @example 1287 * 1288 * var onSuccess = function(widgets) { 1289 * if (widgets.length > 0) { 1290 * alert(widgets[0].value.namespace); 1291 * } 1292 * }; 1293 * 1294 * var onFailure = function(error, status) { 1295 * alert(error); 1296 * }; 1297 * 1298 * Ozone.pref.PrefServer.findWidgets({ 1299 * onSuccess:onSuccess, 1300 * onFailure:onFailure 1301 * }); 1302 */ 1303 findWidgets : function (cfg){ 1304 1305 cfg.url = _url + "/widget"; 1306 if (!cfg.userOnly) { 1307 cfg.url += "/listUserAndGroupWidgets"; 1308 } 1309 1310 // Add search params 1311 var postParams = { 1312 '_method': 'GET' 1313 }; 1314 1315 if (cfg.searchParams) { 1316 if (cfg.searchParams.widgetName && cfg.searchParams.widgetName.length > 0) { 1317 var searchTerm = cfg.searchParams.widgetName; 1318 if (!cfg.searchParams.widgetNameExactMatch) { 1319 searchTerm = '%'+searchTerm+'%'; 1320 } 1321 postParams['widgetName'] = searchTerm; 1322 } 1323 if (cfg.searchParams.widgetVersion && cfg.searchParams.widgetVersion.length > 0) { 1324 postParams['widgetVersion'] = cfg.searchParams.widgetVersion; 1325 } 1326 if (cfg.searchParams.widgetGuid && cfg.searchParams.widgetGuid.length > 0) { 1327 postParams['widgetGuid'] = cfg.searchParams.widgetGuid; 1328 } 1329 if (cfg.searchParams.universalName && cfg.searchParams.universalName.length > 0) { 1330 postParams['universalName'] = cfg.searchParams.universalName; 1331 } 1332 if (cfg.searchParams.group_id) { 1333 postParams['group_id'] = cfg.searchParams.group_id; 1334 } 1335 } 1336 1337 cfg.method = 'POST'; 1338 cfg.content = postParams; 1339 Ozone.util.Transport.send(cfg); 1340 }, 1341 1342 /** 1343 * @description Saves changes to existing widgets 1344 * @param {Object} cfg config object see below for properties 1345 * @param {Array} cfg.widgetsToUpdate array of JSON objects containing the widget guid and data to be updated 1346 * @param {Array} cfg.widgetGuidsToDelete array of guids of widgets to be deleted 1347 * @param {Boolean} cfg.updateOrder flag to update order 1348 * @param {Function} cfg.onSuccess callback function to capture the success result 1349 * @param {Function} [cfg.onFailure] callback to execute if there is an error (optional, a default alert provided) 1350 */ 1351 updateAndDeleteWidgets : function (cfg){ 1352 cfg.url = _url + "/widget"; 1353 var postParams = { 1354 '_method': 'PUT', 1355 'widgetsToUpdate': Ozone.util.toString(cfg.widgetsToUpdate), 1356 'widgetGuidsToDelete': Ozone.util.toString(cfg.widgetGuidsToDelete), 1357 'updateOrder': cfg.updateOrder 1358 }; 1359 1360 cfg.method = 'POST'; 1361 cfg.content = postParams; 1362 Ozone.util.Transport.send(cfg); 1363 }, 1364 1365 /** 1366 * @description Retrieves the user preference for the provided name and namespace 1367 * @param {Object} cfg config object see below for properties 1368 * @param {String} cfg.namespace The namespace of the requested user preference 1369 * @param {String} cfg.name The name of the requested user preference 1370 * @param {Function} cfg.onSuccess The function to be called if the user preference is successfully retrieved from 1371 * the database. This function takes a single argument, which is a JSON object. If a preference is found, the 1372 * complete JSON structure as shown below will be returned. If it is not found this function be passed an empty JSON object. 1373 * @example 1374 * The following is an example of a complete preference object passed to the onSuccess 1375 * function: 1376 * { 1377 * "value":"true", 1378 * "path":"militaryTime", 1379 * "user": 1380 * { 1381 * "userId":"testAdmin1" 1382 * }, 1383 * "namespace":"com.mycompany.AnnouncingClock" 1384 * } 1385 * @param {Function} [cfg.onFailure] This parameter is optional. If this function is not specified a default error 1386 * message will be displayed.This function is called if an error occurs on preference retrieval. It is not 1387 * called if the preference is simply missing. 1388 * This function should accept two arguments:<br> 1389 * <br> 1390 * error: String<br> 1391 * The error message<br> 1392 * <br> 1393 * Status: The numeric HTTP Status code (if applicable)<br> 1394 * 401: You are not authorized to access this entity.<br> 1395 * 500: An unexpected error occurred.<br> 1396 * 404: The user preference was not found.<br> 1397 * 400: The requested entity failed to pass validation.<br> 1398 * @example 1399 * The following shows how to make a call to getUserPreference: 1400 * function onSuccess(pref){ 1401 * alert(Ozone.util.toString(pref.value)); 1402 * } 1403 * 1404 * function onFailure(error,status){ 1405 * alert('Error ' + error); 1406 * alert(status); 1407 * } 1408 * 1409 * // The following code calls getUserPreference with the above defined onSuccess and 1410 * // onFailure callbacks. 1411 * Ozone.pref.PrefServer.getUserPreference({ 1412 * namespace:'com.company.widget', 1413 * name:'First President', 1414 * onSuccess:onSuccess, 1415 * onFailure:onFailure 1416 * }); 1417 */ 1418 getUserPreference : function (cfg){ 1419 cfg.url = _url + "/preference/" + cfg.namespace + "/" + cfg.name; 1420 1421 //igonore 404 error code, onSuccess will be called with emtpy object payload 1422 cfg.ignoredErrorCodes = [404]; 1423 get(cfg); 1424 }, 1425 1426 /** 1427 * @description Checks for the existence of a user preference for a given namespace and name 1428 * @param {Object} cfg config object see below for properties 1429 * @param {String} cfg.namespace The namespace of the requested user 1430 * @param {String} cfg.name The name of the requested user 1431 * @param {Function} cfg.onSuccess The callback function that is called if a preference successfully return from the database. 1432 * This method is passed an object having the following properties:<br> 1433 * <br> 1434 * {Number} statusCode: status code<br> 1435 * {Boolean} preferenceExist: true if preference exists<br> 1436 * <br> 1437 * @param {Function} [cfg.onFailure] The callback function that is called if there was 1438 * an error looking up the preference. This function is <em>not</em> called 1439 * if the preference simply does not exist 1440 * @example 1441 * 1442 * var onSuccess = function(obj) { 1443 * if (obj.statusCode = 200) { 1444 * alert(obj.preferenceExist); 1445 * } 1446 * }; 1447 * 1448 * var onFailure = function(error) { 1449 * alert(error); 1450 * }; 1451 * 1452 * Ozone.pref.PrefServer.doesUserPreferenceExist({ 1453 * namespace:'foo.bar.0', 1454 * name:'test path entry 0', 1455 * onSuccess:onSuccess, 1456 * onFailure:onFailure 1457 * }); 1458 */ 1459 doesUserPreferenceExist: function(cfg) { 1460 cfg.url = _url + "/hasPreference/" + cfg.namespace + "/" + cfg.name; 1461 get(cfg); 1462 }, 1463 1464 /** 1465 * @description retrieves the current user logged into the system 1466 * @param {Object} cfg config object see below for properties 1467 * @param {Function} cfg.onSuccess The callback function that is called for a successful retrieval of the user logged in. 1468 * This method is passed an object having the following properties:<br> 1469 * <br> 1470 * {String} currentUserName: user name<br> 1471 * {String} currentUser: user real name<br> 1472 * {Date} currentUserPrevLogin: previous login date<br> 1473 * {Number} currentId: database pk index<br> 1474 * <br> 1475 * @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. 1476 * @example 1477 * 1478 * var onSuccess = function(obj) { 1479 * if (obj) { 1480 * alert(obj.currentUser); 1481 * } 1482 * }; 1483 * 1484 * var onFailure = function(error) { 1485 * alert(error); 1486 * }; 1487 * 1488 * Ozone.pref.PrefServer.getCurrentUser({ 1489 * onSuccess:onSuccess, 1490 * onFailure:onFailure 1491 * }); 1492 */ 1493 getCurrentUser: function(cfg) { 1494 cfg.url = _url + "/person/whoami"; 1495 get(cfg); 1496 }, 1497 1498 /** 1499 * @description For retrieving the OWF system server version 1500 * @param {Object} cfg config object see below for properties 1501 * @param {Function} cfg.onSuccess The callback function that is called for successfully retrieving the server version of the OWF system. 1502 * This method is passed an object having the following properties:<br> 1503 * <br> 1504 * {String} {serverVersion: server version<br> 1505 * <br> 1506 * @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. 1507 * @example 1508 * 1509 * var onSuccess = function(obj) { 1510 * if (obj) { 1511 * alert(obj.serverVersion); 1512 * } 1513 * }; 1514 * 1515 * var onFailure = function(error) { 1516 * alert(error); 1517 * }; 1518 * 1519 * Ozone.pref.PrefServer.getServerVersion({ 1520 * onSuccess:onSuccess, 1521 * onFailure:onFailure 1522 * }); 1523 */ 1524 getServerVersion: function(cfg) { 1525 cfg.url = _url + "/server/resources"; 1526 get(cfg); 1527 }, 1528 1529 /** 1530 * @description Creates or updates a user preference for the provided namespace and name. 1531 * @param {Object} cfg config object see below for properties 1532 * @param {String} cfg.namespace The namespace of the user preference 1533 * @param {String} cfg.name The name of the user preference 1534 * @param {String} cfg.value The value of the user preference. The value can be any string including JSON. 1535 * @param {Function} cfg.onSuccess The function to be called if the user preference is successfully updated in 1536 * the database. 1537 * @example 1538 * The following is an example of a complete preference object passed to the onSuccess 1539 * function: 1540 * { 1541 * "value":"true", 1542 * "path":"militaryTime", 1543 * "user": 1544 * { 1545 * "userId":"testAdmin1" 1546 * }, 1547 * "namespace":"com.mycompany.AnnouncingClock" 1548 * } 1549 * @param {Function} [cfg.onFailure] The function to be called if the user preference cannot be stored in the database. 1550 * If this function is not specified a default error message will be displayed. This function is passed 1551 * back the following parameters:<br> 1552 * <br> 1553 * error: String<br> 1554 * The error message<br> 1555 * <br> 1556 * Status: The HTTP Status code<br> 1557 * 401: You are not authorized to access this entity.<br> 1558 * 500: An unexpected error occurred.<br> 1559 * 404: The requested entity was not found.<br> 1560 * 400: The requested entity failed to pass validation.<br> 1561 * @example 1562 * 1563 * function onSuccess(pref){ 1564 * alert(pref.value); 1565 * } 1566 * 1567 * function onFailure(error,status){ 1568 * alert('Error ' + error); 1569 * alert(status); 1570 * } 1571 * 1572 * var text = 'George Washington'; 1573 * Ozone.pref.PrefServer.setUserPreference({ 1574 * namespace:'com.company.widget', 1575 * name:'First President', 1576 * value:text, 1577 * onSuccess:onSuccess, 1578 * onFailure:onFailure 1579 * }); 1580 */ 1581 setUserPreference : function (cfg) { 1582 cfg.url = _url + "/preference/" + cfg.namespace + "/" + cfg.name; 1583 if (cfg.method == null) { 1584 cfg.method = 'PUT'; 1585 } 1586 cfg.content = { 1587 '_method': cfg.method, 1588 'value': cfg.value 1589 }; 1590 1591 if (cfg.onSuccess) { 1592 if (!cfg.onFailure) { //must ensure there is an onfailure method, as we using content 1593 cfg.onFailure = function(err) { 1594 alert(Ozone.util.ErrorMessageString.saveUserPreferences + " : " + err); 1595 }; 1596 } 1597 Ozone.util.Transport.send(cfg); 1598 } else { 1599 Ozone.util.Transport.sendAndForget(cfg); 1600 } 1601 }, 1602 1603 /** 1604 * @description Deletes a user preference with the provided namespace and name. 1605 * @param {Object} cfg config object see below for properties 1606 * @param {String} cfg.namespace The namespace of the user preference 1607 * @param {String} cfg.name The name of the user preference 1608 * @param {Function} cfg.onSuccess The function to be called if the user preference is successfully deleted from the database. 1609 * @example 1610 * The following is an example of a complete preference object passed to the onSuccess 1611 * function: 1612 * 1613 * { 1614 * "value":"true", 1615 * "path":"militaryTime", 1616 * "user": 1617 * { 1618 * "userId":"testAdmin1" 1619 * }, 1620 * "namespace":"com.mycompany.AnnouncingClock" 1621 * } 1622 * @param {Function} [cfg.onFailure] The function to be called if the user preference cannot be deleted from the 1623 * database or if the preference does not exist. If this function is not specified a default error message will be 1624 * displayed. This function is passed back the following parameters: <br> 1625 * <br> 1626 * error: String <br> 1627 * The error message <br> 1628 * <br> 1629 * Status: The HTTP Status code<br> 1630 * <br> 1631 * 401: You are not authorized to access this entity.<br> 1632 * 500: An unexpected error occurred.<br> 1633 * 404: The user preference was not found.<br> 1634 * 400: The requested entity failed to pass validation. <br> 1635 * <br> 1636 * @example 1637 * function onSuccess(pref){ 1638 * alert(pref.value); 1639 * } 1640 * 1641 * function onFailure(error,status){ 1642 * alert('Error ' + error); 1643 * alert(status); 1644 * } 1645 * 1646 * Ozone.pref.PrefServer.deleteUserPreference({ 1647 * namespace:'com.company.widget', 1648 * name:'First President', 1649 * onSuccess:onSuccess, 1650 * onFailure:onFailure 1651 * }); 1652 */ 1653 deleteUserPreference : function (cfg){ 1654 cfg.method = "DELETE"; 1655 //igonore 404 error code, onSuccess will be called with null payload 1656 cfg.ignoredErrorCodes = [404]; 1657 cfg.path = cfg.name; 1658 Ozone.pref.PrefServer.setUserPreference(cfg); 1659 }, 1660 1661 /** 1662 * @private 1663 */ 1664 getDependentWidgets : function (cfg) { 1665 cfg.url = _url + '/widgetDefinition/dependents'; 1666 cfg.method = 'POST'; 1667 if (!cfg.content) { cfg.content = {}; } 1668 Ozone.util.Transport.send(cfg); 1669 }, 1670 1671 /** 1672 * @private 1673 */ 1674 getDependentPersonWidgets : function (cfg) { 1675 cfg.url = _url + '/personWidgetDefinition/dependents'; 1676 cfg.method = 'POST'; 1677 if (!cfg.content) { cfg.content = {}; } 1678 Ozone.util.Transport.send(cfg); 1679 }, 1680 1681 /** 1682 * @private 1683 */ 1684 deleteWidgetDefs : function (cfg) { 1685 cfg.url = _url + '/widgetDefinition'; 1686 cfg.method = 'DELETE'; 1687 if (!cfg.content) { cfg.content = {}; } 1688 Ozone.util.Transport.send(cfg); 1689 } 1690 1691 }; 1692 }; 1693 1694 var configParams = Ozone.util.parseWindowNameData(); 1695 var url = null; 1696 if (configParams != null && configParams.preferenceLocation != null) { 1697 url = configParams.preferenceLocation; 1698 } 1699 else { 1700 url = Ozone.config.prefsLocation; 1701 } 1702 1703 Ozone.pref.PrefServer = Ozone.pref.PrefServer(url); 1704 if(url == null) { 1705 for (var fname in Ozone.pref.PrefServer) { 1706 if (typeof Ozone.pref.PrefServer[fname] == 'function') { 1707 //dummyfy 1708 Ozone.pref.PrefServer[fname] = function(){}; 1709 } 1710 } 1711 } 1712 }(window, document)); 1713