dashboard.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // jQuery UI style "widget" for editing an iTop "dashboard"
  2. $(function()
  3. {
  4. // the widget definition, where "itop" is the namespace,
  5. // "dashboard" the widget name
  6. $.widget( "itop.dashboard",
  7. {
  8. // default options
  9. options:
  10. {
  11. dashboard_id: '',
  12. layout_class: '',
  13. title: '',
  14. submit_to: 'index.php',
  15. submit_parameters: {operation: 'async_action'}
  16. },
  17. // the constructor
  18. _create: function()
  19. {
  20. var me = this;
  21. this.element
  22. .addClass('itop-dashboard');
  23. this.ajax_div = $('<div></div>').appendTo(this.element);
  24. },
  25. // called when created, and later when changing options
  26. _refresh: function()
  27. {
  28. },
  29. // events bound via _bind are removed automatically
  30. // revert other modifications here
  31. destroy: function()
  32. {
  33. this.element
  34. .removeClass('itop-dashboard');
  35. this.ajax_div.remove();
  36. // call the original destroy method since we overwrote it
  37. $.Widget.prototype.destroy.call( this );
  38. },
  39. // _setOptions is called with a hash of all options that are changing
  40. _setOptions: function()
  41. {
  42. // in 1.9 would use _superApply
  43. $.Widget.prototype._setOptions.apply( this, arguments );
  44. this._refresh();
  45. },
  46. // _setOption is called for each individual option that is changing
  47. _setOption: function( key, value )
  48. {
  49. // in 1.9 would use _super
  50. $.Widget.prototype._setOption.call( this, key, value );
  51. },
  52. save: function()
  53. {
  54. var oParams = this.options.submit_parameters;
  55. oParams.dashlets = [];
  56. this.element.find(':itop-dashlet').each(function() {
  57. var oDashlet = $(this).data('dashlet');
  58. if(oDashlet)
  59. {
  60. var sId = $(this).attr('id');
  61. var oDashletParams = oDashlet.get_params();
  62. oParams['dashlet_'+sId] = oDashletParams;
  63. oParams.dashlets.push({dashlet_id: sId, dashlet_class: oDashletParams['dashlet_class']} );
  64. }
  65. });
  66. oParams.dashboard_id = this.options.dashboard_id;
  67. oParams.layout_class = this.options.layout_class;
  68. oParams.title = this.options.title;
  69. var me = this;
  70. $.post(this.options.submit_to, oParams, function(data){
  71. me.ajax_div.html(data);
  72. });
  73. }
  74. });
  75. });