appconfig.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. $.ajax({
  40. type: method.toUpperCase(),
  41. url: OC.linkToOCS('apps/provisioning_api/api/v1', 2) + 'config/apps' + endpoint,
  42. data: options.data || {},
  43. success: options.success,
  44. error: options.error
  45. });
  46. },
  47. /**
  48. * @param {Object} [options]
  49. * @param {function} [options.success]
  50. * @since 11.0.0
  51. */
  52. getApps: function(options) {
  53. this._call('get', '', options);
  54. },
  55. /**
  56. * @param {string} app
  57. * @param {Object} [options]
  58. * @param {function} [options.success]
  59. * @param {function} [options.error]
  60. * @since 11.0.0
  61. */
  62. getKeys: function(app, options) {
  63. this._call('get', '/' + app, options);
  64. },
  65. /**
  66. * @param {string} app
  67. * @param {string} key
  68. * @param {string|function} defaultValue
  69. * @param {Object} [options]
  70. * @param {function} [options.success]
  71. * @param {function} [options.error]
  72. * @since 11.0.0
  73. */
  74. getValue: function(app, key, defaultValue, options) {
  75. options = options || {};
  76. options['data'] = {
  77. defaultValue: defaultValue
  78. };
  79. this._call('get', '/' + app + '/' + key, options);
  80. },
  81. /**
  82. * @param {string} app
  83. * @param {string} key
  84. * @param {string} value
  85. * @param {Object} [options]
  86. * @param {function} [options.success]
  87. * @param {function} [options.error]
  88. * @since 11.0.0
  89. */
  90. setValue: function(app, key, value, options) {
  91. options = options || {};
  92. options['data'] = {
  93. value: value
  94. };
  95. this._call('post', '/' + app + '/' + key, options);
  96. },
  97. /**
  98. * @param {string} app
  99. * @param {string} key
  100. * @param {Object} [options]
  101. * @param {function} [options.success]
  102. * @param {function} [options.error]
  103. * @since 11.0.0
  104. */
  105. deleteKey: function(app, key, options) {
  106. this._call('delete', '/' + app + '/' + key, options);
  107. }
  108. };