appconfig.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /**
  2. * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
  3. *
  4. * @license GNU AGPL version 3 or any later version
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as
  8. * published by the Free Software Foundation, either version 3 of the
  9. * License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. /**
  21. * @namespace
  22. * @since 11.0.0
  23. */
  24. OCP.AppConfig = {
  25. /**
  26. * @param {string} method
  27. * @param {string} endpoint
  28. * @param {Object} [options]
  29. * @param {Object} [options.data]
  30. * @param {function} [options.success]
  31. * @param {function} [options.error]
  32. * @internal
  33. */
  34. _call: function(method, endpoint, options) {
  35. if ((method === 'post' || method === 'delete') && OC.PasswordConfirmation.requiresPasswordConfirmation()) {
  36. OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this._call, this, method, endpoint, options));
  37. return;
  38. }
  39. options = options || {};
  40. $.ajax({
  41. type: method.toUpperCase(),
  42. url: OC.linkToOCS('apps/provisioning_api/api/v1', 2) + 'config/apps' + endpoint,
  43. data: options.data || {},
  44. success: options.success,
  45. error: options.error
  46. });
  47. },
  48. /**
  49. * @param {Object} [options]
  50. * @param {function} [options.success]
  51. * @since 11.0.0
  52. */
  53. getApps: function(options) {
  54. this._call('get', '', options);
  55. },
  56. /**
  57. * @param {string} app
  58. * @param {Object} [options]
  59. * @param {function} [options.success]
  60. * @param {function} [options.error]
  61. * @since 11.0.0
  62. */
  63. getKeys: function(app, options) {
  64. this._call('get', '/' + app, options);
  65. },
  66. /**
  67. * @param {string} app
  68. * @param {string} key
  69. * @param {string|function} defaultValue
  70. * @param {Object} [options]
  71. * @param {function} [options.success]
  72. * @param {function} [options.error]
  73. * @since 11.0.0
  74. */
  75. getValue: function(app, key, defaultValue, options) {
  76. options = options || {};
  77. options['data'] = {
  78. defaultValue: defaultValue
  79. };
  80. this._call('get', '/' + app + '/' + key, options);
  81. },
  82. /**
  83. * @param {string} app
  84. * @param {string} key
  85. * @param {string} value
  86. * @param {Object} [options]
  87. * @param {function} [options.success]
  88. * @param {function} [options.error]
  89. * @since 11.0.0
  90. */
  91. setValue: function(app, key, value, options) {
  92. options = options || {};
  93. options['data'] = {
  94. value: value
  95. };
  96. this._call('post', '/' + app + '/' + key, options);
  97. },
  98. /**
  99. * @param {string} app
  100. * @param {string} key
  101. * @param {Object} [options]
  102. * @param {function} [options.success]
  103. * @param {function} [options.error]
  104. * @since 11.0.0
  105. */
  106. deleteKey: function(app, key, options) {
  107. this._call('delete', '/' + app + '/' + key, options);
  108. }
  109. };