dashlet.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // jQuery UI style "widget" for editing an iTop "dashlet"
  2. $(function()
  3. {
  4. // the widget definition, where "itop" is the namespace,
  5. // "dashlet" the widget name
  6. $.widget( "itop.dashlet",
  7. {
  8. // default options
  9. options:
  10. {
  11. dashlet_id: '',
  12. dashlet_class: ''
  13. },
  14. // the constructor
  15. _create: function()
  16. {
  17. var me = this;
  18. this.element
  19. .addClass('itop-dashlet')
  20. .bind('click.itop-dashlet', function(event) { me._on_click(event); } );
  21. },
  22. // called when created, and later when changing options
  23. _refresh: function()
  24. {
  25. },
  26. // events bound via _bind are removed automatically
  27. // revert other modifications here
  28. destroy: function()
  29. {
  30. this.element
  31. .removeClass('itop-dashlet')
  32. .unbind('click.itop-dashlet');
  33. // call the original destroy method since we overwrote it
  34. $.Widget.prototype.destroy.call( this );
  35. },
  36. // _setOptions is called with a hash of all options that are changing
  37. _setOptions: function()
  38. {
  39. // in 1.9 would use _superApply
  40. $.Widget.prototype._setOptions.apply( this, arguments );
  41. },
  42. // _setOption is called for each individual option that is changing
  43. _setOption: function( key, value )
  44. {
  45. // in 1.9 would use _super
  46. $.Widget.prototype._setOption.call( this, key, value );
  47. },
  48. _select: function()
  49. {
  50. this.element.addClass('dashlet-selected');
  51. $('#event_bus').trigger('dashlet-selected', {'dashlet_id': this.options.dashlet_id, 'dashlet_class': this.options.dashlet_class})
  52. },
  53. _deselect: function()
  54. {
  55. this.element.removeClass('dashlet-selected');
  56. },
  57. _on_click: function(event)
  58. {
  59. var sCurrentId = this.element.attr('id');
  60. $(':itop-dashlet').each(function(){
  61. var sId = $(this).attr('id');
  62. var oWidget = $(this).data('dashlet');
  63. if (oWidget)
  64. {
  65. if (sCurrentId != sId)
  66. {
  67. oWidget._deselect();
  68. }
  69. }
  70. });
  71. this._select();
  72. }
  73. });
  74. });