1
0

module.js 4.1 KB

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