module.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. $(oCheckbox).attr('checked', 'checked').trigger('enable');
  43. return;
  44. }
  45. if(iWidgetId != 0 && oData.widget.length > 0) {
  46. $('#bx-std-widget-' + iWidgetId).replaceWith(oData.widget);
  47. if(oBxDolStudioLauncher.bJitterMode)
  48. oBxDolStudioLauncher.enableJitter(); // the fresh tile needs its edit-mode controls shown
  49. return;
  50. }
  51. $('#bx-std-page-columns').bx_anim('hide', $this.sAnimationEffect, $this.iAnimationSpeed, function() {
  52. $(this).html(oData.content);
  53. if(oData.content.length > 0)
  54. $(this).bxProcessHtml().bx_anim('show', $this.sAnimationEffect, 'fast');
  55. });
  56. },
  57. 'json'
  58. );
  59. return true;
  60. };
  61. BxDolStudioModule.prototype.uninstall = function(sName, iWidgetId, iConfirm) {
  62. if(!sName)
  63. return false;
  64. var oDate = new Date();
  65. var aParams = {_t:oDate.getTime()};
  66. aParams[this.sActionsPrefix + '_action'] = 'uninstall';
  67. aParams[this.sActionsPrefix + '_value'] = sName;
  68. aParams[this.sActionsPrefix + '_widget_id'] = iWidgetId;
  69. aParams[this.sActionsPrefix + '_confirmed'] = parseInt(iConfirm);
  70. $('.bx-popup-applied:visible').dolPopupHide();
  71. $.get(
  72. this.sActionsUrl, aParams, function (oData) {
  73. processJsonData(oData);
  74. },
  75. 'json'
  76. );
  77. };
  78. BxDolStudioModule.prototype.onUninstall = function(oData) {
  79. if(oData.code != 0 || oData.page.length == 0 || oData.widget_id.length == 0)
  80. return;
  81. // uninstalled from the app's own page: the page is gone, back to the launcher
  82. if(window.location.pathname.indexOf('module.php') != -1 && window.location.search.indexOf('name=' + oData.page) != -1) {
  83. window.location = sUrlStudio + 'launcher.php';
  84. return;
  85. }
  86. $('#bx-menu-item-' + oData.page).bx_anim('hide', this.sAnimationEffect, this.iAnimationSpeed, function() {
  87. $(this).remove();
  88. });
  89. $('#bx-std-widget-' + oData.widget_id).bx_anim('hide', this.sAnimationEffect, this.iAnimationSpeed, function() {
  90. $(this).remove();
  91. });
  92. };
  93. /** @} */