module.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. * Copyright (c) UNA, Inc - https://una.io
  3. * MIT License - https://opensource.org/licenses/MIT
  4. *
  5. * @defgroup UnaStudio UNA Studio
  6. * @{
  7. */
  8. function BxDolStudioModule(oOptions) {
  9. this.sActionsUrl = oOptions.sActionUrl;
  10. this.sActionsPrefix = oOptions.sActionsPrefix;
  11. this.sObjName = oOptions.sObjName == undefined ? 'oBxDolStudioModule' : oOptions.sObjName;
  12. this.sAnimationEffect = oOptions.sAnimationEffect == undefined ? 'fade' : oOptions.sAnimationEffect;
  13. this.iAnimationSpeed = oOptions.iAnimationSpeed == undefined ? 'slow' : oOptions.iAnimationSpeed;
  14. }
  15. BxDolStudioModule.prototype.settings = function(sName, iWidgetId) {
  16. if(!sName)
  17. return false;
  18. var oDate = new Date();
  19. var aParams = {_t:oDate.getTime()};
  20. aParams[this.sActionsPrefix + '_action'] = 'settings';
  21. aParams[this.sActionsPrefix + '_value'] = sName;
  22. aParams[this.sActionsPrefix + '_widget_id'] = iWidgetId;
  23. $.get(
  24. this.sActionsUrl, aParams, function(oData) {
  25. processJsonData(oData);
  26. },
  27. 'json'
  28. );
  29. };
  30. BxDolStudioModule.prototype.activate = function(oCheckbox, sName, iWidgetId) {
  31. var $this = this;
  32. var oDate = new Date();
  33. var aParams = {_t:oDate.getTime()};
  34. aParams[this.sActionsPrefix + '_action'] = 'activate';
  35. aParams[this.sActionsPrefix + '_value'] = sName;
  36. aParams[this.sActionsPrefix + '_widget_id'] = iWidgetId;
  37. $.get(
  38. this.sActionsUrl, aParams, function(oData) {
  39. processJsonData(oData);
  40. $('.bx-popup-applied:visible').dolPopupHide();
  41. if(oData.code != 0) {
  42. bx_sound('error'); // the switch goes back
  43. $(oCheckbox).attr('checked', 'checked').trigger('enable');
  44. return;
  45. }
  46. // the app's dock item dims or brightens with it (the launcher tile is replaced below)
  47. if(oData.page)
  48. $('#bx-menu-item-' + oData.page).toggleClass('bx-menu-item-disabled', !parseInt(oData.enabled));
  49. if(iWidgetId != 0 && oData.widget.length > 0) {
  50. $('#bx-std-widget-' + iWidgetId).replaceWith(oData.widget);
  51. if(oBxDolStudioLauncher.bJitterMode)
  52. oBxDolStudioLauncher.enableJitter(); // the fresh tile needs its edit-mode controls shown
  53. return;
  54. }
  55. $('#bx-std-page-columns').bx_anim('hide', $this.sAnimationEffect, $this.iAnimationSpeed, function() {
  56. $(this).html(oData.content);
  57. if(oData.content.length > 0)
  58. $(this).bxProcessHtml().bx_anim('show', $this.sAnimationEffect, 'fast');
  59. });
  60. },
  61. 'json'
  62. );
  63. return true;
  64. };
  65. BxDolStudioModule.prototype.uninstall = function(sName, iWidgetId, iConfirm) {
  66. if(!sName)
  67. return false;
  68. var oDate = new Date();
  69. var aParams = {_t:oDate.getTime()};
  70. aParams[this.sActionsPrefix + '_action'] = 'uninstall';
  71. aParams[this.sActionsPrefix + '_value'] = sName;
  72. aParams[this.sActionsPrefix + '_widget_id'] = iWidgetId;
  73. aParams[this.sActionsPrefix + '_confirmed'] = parseInt(iConfirm);
  74. $('.bx-popup-applied:visible').dolPopupHide();
  75. $.get(
  76. this.sActionsUrl, aParams, function (oData) {
  77. processJsonData(oData);
  78. },
  79. 'json'
  80. );
  81. };
  82. BxDolStudioModule.prototype.onUninstall = function(oData) {
  83. if(oData.code != 0 || oData.page.length == 0 || oData.widget_id.length == 0)
  84. return;
  85. // uninstalled from the app's own page: the page is gone, back to the launcher
  86. if(window.location.pathname.indexOf('module.php') != -1 && window.location.search.indexOf('name=' + oData.page) != -1) {
  87. window.location = sUrlStudio + 'launcher.php';
  88. return;
  89. }
  90. $('#bx-menu-item-' + oData.page).bx_anim('hide', this.sAnimationEffect, this.iAnimationSpeed, function() {
  91. $(this).remove();
  92. });
  93. $('#bx-std-widget-' + oData.widget_id).bx_anim('hide', this.sAnimationEffect, this.iAnimationSpeed, function() {
  94. $(this).remove();
  95. });
  96. };
  97. /** @} */