apps.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. /* global Handlebars */
  2. Handlebars.registerHelper('score', function() {
  3. if(this.score) {
  4. var score = Math.round( this.score / 10 );
  5. var imageName = 'rating/s' + score + '.svg';
  6. return new Handlebars.SafeString('<img src="' + OC.imagePath('core', imageName) + '">');
  7. }
  8. return new Handlebars.SafeString('');
  9. });
  10. Handlebars.registerHelper('level', function() {
  11. if(typeof this.level !== 'undefined') {
  12. if(this.level === 200) {
  13. return new Handlebars.SafeString('<span class="official icon-checkmark">' + t('settings', 'Official') + '</span>');
  14. } else if(this.level === 100) {
  15. return new Handlebars.SafeString('<span class="approved">' + t('settings', 'Approved') + '</span>');
  16. } else {
  17. return new Handlebars.SafeString('<span class="experimental">' + t('settings', 'Experimental') + '</span>');
  18. }
  19. }
  20. });
  21. OC.Settings = OC.Settings || {};
  22. OC.Settings.Apps = OC.Settings.Apps || {
  23. setupGroupsSelect: function($elements) {
  24. OC.Settings.setupGroupsSelect($elements, {
  25. placeholder: t('core', 'All')
  26. });
  27. },
  28. State: {
  29. currentCategory: null,
  30. apps: null
  31. },
  32. loadCategories: function() {
  33. if (this._loadCategoriesCall) {
  34. this._loadCategoriesCall.abort();
  35. }
  36. var categories = [
  37. {displayName: t('settings', 'Enabled'), ident: 'enabled', id: '0'},
  38. {displayName: t('settings', 'Not enabled'), ident: 'disabled', id: '1'}
  39. ];
  40. var source = $("#categories-template").html();
  41. var template = Handlebars.compile(source);
  42. var html = template(categories);
  43. $('#apps-categories').html(html);
  44. OC.Settings.Apps.loadCategory($('#app-navigation').attr('data-category'));
  45. this._loadCategoriesCall = $.ajax(OC.generateUrl('settings/apps/categories'), {
  46. data:{},
  47. type:'GET',
  48. success:function (jsondata) {
  49. var html = template(jsondata);
  50. $('#apps-categories').html(html);
  51. $('#app-category-' + OC.Settings.Apps.State.currentCategory).addClass('active');
  52. },
  53. complete: function() {
  54. $('#app-navigation').removeClass('icon-loading');
  55. }
  56. });
  57. },
  58. loadCategory: function(categoryId) {
  59. if (OC.Settings.Apps.State.currentCategory === categoryId) {
  60. return;
  61. }
  62. if (this._loadCategoryCall) {
  63. this._loadCategoryCall.abort();
  64. }
  65. $('#apps-list')
  66. .addClass('icon-loading')
  67. .removeClass('hidden')
  68. .html('');
  69. $('#apps-list-empty').addClass('hidden');
  70. $('#app-category-' + OC.Settings.Apps.State.currentCategory).removeClass('active');
  71. $('#app-category-' + categoryId).addClass('active');
  72. OC.Settings.Apps.State.currentCategory = categoryId;
  73. this._loadCategoryCall = $.ajax(OC.generateUrl('settings/apps/list?category={categoryId}&includeUpdateInfo=0', {
  74. categoryId: categoryId
  75. }), {
  76. type:'GET',
  77. success: function (apps) {
  78. var appListWithIndex = _.indexBy(apps.apps, 'id');
  79. OC.Settings.Apps.State.apps = appListWithIndex;
  80. var appList = _.map(appListWithIndex, function(app) {
  81. // default values for missing fields
  82. return _.extend({level: 0}, app);
  83. });
  84. var source = $("#app-template").html();
  85. var template = Handlebars.compile(source);
  86. if (appList.length) {
  87. appList.sort(function(a,b) {
  88. var levelDiff = b.level - a.level;
  89. if (levelDiff === 0) {
  90. return OC.Util.naturalSortCompare(a.name, b.name);
  91. }
  92. return levelDiff;
  93. });
  94. var firstExperimental = false;
  95. _.each(appList, function(app) {
  96. if(app.level === 0 && firstExperimental === false) {
  97. firstExperimental = true;
  98. OC.Settings.Apps.renderApp(app, template, null, true);
  99. } else {
  100. OC.Settings.Apps.renderApp(app, template, null, false);
  101. }
  102. });
  103. } else {
  104. $('#apps-list').addClass('hidden');
  105. $('#apps-list-empty').removeClass('hidden').find('h2').text(t('settings', 'No apps found for your version'));
  106. }
  107. $('.enable.needs-download').tooltip({
  108. title: t('settings', 'The app will be downloaded from the app store'),
  109. placement: 'bottom',
  110. container: 'body'
  111. });
  112. $('.app-level .official').tooltip({
  113. title: t('settings', 'Official apps are developed by and within the community. They offer central functionality and are ready for production use.'),
  114. placement: 'bottom',
  115. container: 'body'
  116. });
  117. $('.app-level .approved').tooltip({
  118. title: t('settings', 'Approved apps are developed by trusted developers and have passed a cursory security check. They are actively maintained in an open code repository and their maintainers deem them to be stable for casual to normal use.'),
  119. placement: 'bottom',
  120. container: 'body'
  121. });
  122. $('.app-level .experimental').tooltip({
  123. title: t('settings', 'This app is not checked for security issues and is new or known to be unstable. Install at your own risk.'),
  124. placement: 'bottom',
  125. container: 'body'
  126. });
  127. },
  128. complete: function() {
  129. var availableUpdates = 0;
  130. $('#apps-list').removeClass('icon-loading');
  131. $.ajax(OC.generateUrl('settings/apps/list?category={categoryId}&includeUpdateInfo=1', {
  132. categoryId: categoryId
  133. }), {
  134. type: 'GET',
  135. success: function (apps) {
  136. _.each(apps.apps, function(app) {
  137. if (app.update) {
  138. var $update = $('#app-' + app.id + ' .update');
  139. $update.removeClass('hidden');
  140. $update.val(t('settings', 'Update to %s').replace(/%s/g, app.update));
  141. availableUpdates++;
  142. OC.Settings.Apps.State.apps[app.id].update = true;
  143. }
  144. });
  145. if (availableUpdates > 0) {
  146. OC.Notification.show(n('settings', 'You have %n app update pending', 'You have %n app updates pending', availableUpdates));
  147. }
  148. }
  149. });
  150. }
  151. });
  152. },
  153. renderApp: function(app, template, selector, firstExperimental) {
  154. if (!template) {
  155. var source = $("#app-template").html();
  156. template = Handlebars.compile(source);
  157. }
  158. if (typeof app === 'string') {
  159. app = OC.Settings.Apps.State.apps[app];
  160. }
  161. app.firstExperimental = firstExperimental;
  162. if (!app.preview) {
  163. app.preview = OC.imagePath('core', 'default-app-icon');
  164. app.previewAsIcon = true;
  165. }
  166. var html = template(app);
  167. if (selector) {
  168. selector.html(html);
  169. } else {
  170. $('#apps-list').append(html);
  171. }
  172. var page = $('#app-' + app.id);
  173. // image loading kung-fu (IE doesn't properly scale SVGs, so disable app icons)
  174. if (app.preview && !OC.Util.isIE()) {
  175. var currentImage = new Image();
  176. currentImage.src = app.preview;
  177. }
  178. currentImage.onload = function() {
  179. page.find('.app-image')
  180. .append(OC.Settings.Apps.imageUrl(app.preview, app.detailpage))
  181. .fadeIn();
  182. };
  183. // set group select properly
  184. if(OC.Settings.Apps.isType(app, 'filesystem') || OC.Settings.Apps.isType(app, 'prelogin') ||
  185. OC.Settings.Apps.isType(app, 'authentication') || OC.Settings.Apps.isType(app, 'logging') ||
  186. OC.Settings.Apps.isType(app, 'prevent_group_restriction')) {
  187. page.find(".groups-enable").hide();
  188. page.find(".groups-enable__checkbox").prop('checked', false);
  189. } else {
  190. page.find('#group_select').val((app.groups || []).join('|'));
  191. if (app.active) {
  192. if (app.groups.length) {
  193. OC.Settings.Apps.setupGroupsSelect(page.find('#group_select'));
  194. page.find(".groups-enable__checkbox").prop('checked', true);
  195. } else {
  196. page.find(".groups-enable__checkbox").prop('checked', false);
  197. }
  198. page.find(".groups-enable").show();
  199. } else {
  200. page.find(".groups-enable").hide();
  201. }
  202. }
  203. },
  204. /**
  205. * Returns the image for apps listing
  206. * url : the url of the image
  207. * appfromstore: bool to check whether the app is fetched from store or not.
  208. */
  209. imageUrl : function (url, appfromstore) {
  210. var img = '<svg width="72" height="72" viewBox="0 0 72 72">';
  211. if (appfromstore) {
  212. img += '<image x="0" y="0" width="72" height="72" preserveAspectRatio="xMinYMin meet" xlink:href="' + url + '" class="app-icon" /></svg>';
  213. } else {
  214. img += '<defs><filter id="invert"><feColorMatrix in="SourceGraphic" type="matrix" values="-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0" /></filter></defs>';
  215. img += '<image x="0" y="0" width="72" height="72" preserveAspectRatio="xMinYMin meet" filter="url(#invert)" xlink:href="' + url + '" class="app-icon" /></svg>';
  216. }
  217. return img;
  218. },
  219. isType: function(app, type){
  220. return app.types && app.types.indexOf(type) !== -1;
  221. },
  222. /**
  223. * Checks the server health.
  224. *
  225. * If the promise fails, the server is broken.
  226. *
  227. * @return {Promise} promise
  228. */
  229. _checkServerHealth: function() {
  230. return $.get(OC.generateUrl('apps/files'));
  231. },
  232. enableApp:function(appId, active, element, groups) {
  233. var self = this;
  234. OC.Settings.Apps.hideErrorMessage(appId);
  235. groups = groups || [];
  236. var appItem = $('div#app-'+appId+'');
  237. element.val(t('settings','Please wait....'));
  238. if(active && !groups.length) {
  239. $.post(OC.filePath('settings','ajax','disableapp.php'),{appid:appId},function(result) {
  240. if(!result || result.status !== 'success') {
  241. if (result.data && result.data.message) {
  242. OC.Settings.Apps.showErrorMessage(appId, result.data.message);
  243. appItem.data('errormsg', result.data.message);
  244. } else {
  245. OC.Settings.Apps.showErrorMessage(appId, t('settings', 'Error while disabling app'));
  246. appItem.data('errormsg', t('settings', 'Error while disabling app'));
  247. }
  248. element.val(t('settings','Disable'));
  249. appItem.addClass('appwarning');
  250. } else {
  251. OC.Settings.Apps.rebuildNavigation();
  252. appItem.data('active',false);
  253. appItem.data('groups', '');
  254. element.data('active',false);
  255. appItem.removeClass('active');
  256. element.val(t('settings','Enable'));
  257. element.parent().find(".groups-enable").hide();
  258. element.parent().find('#group_select').hide().val(null);
  259. OC.Settings.Apps.State.apps[appId].active = false;
  260. }
  261. },'json');
  262. } else {
  263. // TODO: display message to admin to not refresh the page!
  264. // TODO: lock UI to prevent further operations
  265. $.post(OC.filePath('settings','ajax','enableapp.php'),{appid: appId, groups: groups},function(result) {
  266. if(!result || result.status !== 'success') {
  267. if (result.data && result.data.message) {
  268. OC.Settings.Apps.showErrorMessage(appId, result.data.message);
  269. appItem.data('errormsg', result.data.message);
  270. } else {
  271. OC.Settings.Apps.showErrorMessage(appId, t('settings', 'Error while enabling app'));
  272. appItem.data('errormsg', t('settings', 'Error while disabling app'));
  273. }
  274. element.val(t('settings','Enable'));
  275. appItem.addClass('appwarning');
  276. } else {
  277. self._checkServerHealth().done(function() {
  278. if (result.data.update_required) {
  279. OC.Settings.Apps.showReloadMessage();
  280. setTimeout(function() {
  281. location.reload();
  282. }, 5000);
  283. }
  284. OC.Settings.Apps.rebuildNavigation();
  285. appItem.data('active',true);
  286. element.data('active',true);
  287. appItem.addClass('active');
  288. element.val(t('settings','Disable'));
  289. var app = OC.Settings.Apps.State.apps[appId];
  290. app.active = true;
  291. if (OC.Settings.Apps.isType(app, 'filesystem') || OC.Settings.Apps.isType(app, 'prelogin') ||
  292. OC.Settings.Apps.isType(app, 'authentication') || OC.Settings.Apps.isType(app, 'logging')) {
  293. element.parent().find(".groups-enable").prop('checked', true);
  294. element.parent().find(".groups-enable").hide();
  295. element.parent().find('#group_select').hide().val(null);
  296. } else {
  297. element.parent().find("#groups-enable").show();
  298. if (groups) {
  299. appItem.data('groups', JSON.stringify(groups));
  300. } else {
  301. appItem.data('groups', '');
  302. }
  303. }
  304. }).fail(function() {
  305. // server borked, emergency disable app
  306. $.post(OC.webroot + '/index.php/disableapp', {appid: appId}, function() {
  307. OC.Settings.Apps.showErrorMessage(
  308. appId,
  309. t('settings', 'Error: this app cannot be enabled because it makes the server unstable')
  310. );
  311. appItem.data('errormsg', t('settings', 'Error while enabling app'));
  312. element.val(t('settings','Enable'));
  313. appItem.addClass('appwarning');
  314. }).fail(function() {
  315. OC.Settings.Apps.showErrorMessage(
  316. appId,
  317. t('settings', 'Error: could not disable broken app')
  318. );
  319. appItem.data('errormsg', t('settings', 'Error while disabling broken app'));
  320. element.val(t('settings','Enable'));
  321. });
  322. });
  323. }
  324. },'json')
  325. .fail(function() {
  326. OC.Settings.Apps.showErrorMessage(appId, t('settings', 'Error while enabling app'));
  327. appItem.data('errormsg', t('settings', 'Error while enabling app'));
  328. appItem.data('active',false);
  329. appItem.addClass('appwarning');
  330. element.val(t('settings','Enable'));
  331. });
  332. }
  333. },
  334. updateApp:function(appId, element) {
  335. var oldButtonText = element.val();
  336. element.val(t('settings','Updating....'));
  337. OC.Settings.Apps.hideErrorMessage(appId);
  338. $.post(OC.filePath('settings','ajax','updateapp.php'),{appid:appId},function(result) {
  339. if(!result || result.status !== 'success') {
  340. if (result.data && result.data.message) {
  341. OC.Settings.Apps.showErrorMessage(appId, result.data.message);
  342. } else {
  343. OC.Settings.Apps.showErrorMessage(appId, t('settings','Error while updating app'));
  344. }
  345. element.val(oldButtonText);
  346. }
  347. else {
  348. element.val(t('settings','Updated'));
  349. element.hide();
  350. }
  351. },'json');
  352. },
  353. uninstallApp:function(appId, element) {
  354. OC.Settings.Apps.hideErrorMessage(appId);
  355. element.val(t('settings','Uninstalling ....'));
  356. $.post(OC.filePath('settings','ajax','uninstallapp.php'),{appid:appId},function(result) {
  357. if(!result || result.status !== 'success') {
  358. OC.Settings.Apps.showErrorMessage(appId, t('settings','Error while uninstalling app'));
  359. element.val(t('settings','Uninstall'));
  360. } else {
  361. OC.Settings.Apps.rebuildNavigation();
  362. element.parent().fadeOut(function() {
  363. element.remove();
  364. });
  365. }
  366. },'json');
  367. },
  368. rebuildNavigation: function() {
  369. $.getJSON(OC.filePath('settings', 'ajax', 'navigationdetect.php')).done(function(response){
  370. if(response.status === 'success'){
  371. var idsToKeep = {};
  372. var navEntries=response.nav_entries;
  373. var container = $('#apps ul');
  374. for(var i=0; i< navEntries.length; i++){
  375. var entry = navEntries[i];
  376. idsToKeep[entry.id] = true;
  377. if(container.children('li[data-id="'+entry.id+'"]').length === 0){
  378. var li=$('<li></li>');
  379. li.attr('data-id', entry.id);
  380. var img = '<svg width="32" height="32" viewBox="0 0 32 32">';
  381. img += '<defs><filter id="invert"><feColorMatrix in="SourceGraphic" type="matrix" values="-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0" /></filter></defs>';
  382. img += '<image x="0" y="0" width="32" height="32" preserveAspectRatio="xMinYMin meet" filter="url(#invert)" xlink:href="' + entry.icon + '" class="app-icon" /></svg>';
  383. var a=$('<a></a>').attr('href', entry.href);
  384. var filename=$('<span></span>');
  385. var loading = $('<div class="icon-loading-dark"></div>').css('display', 'none');
  386. filename.text(entry.name);
  387. a.prepend(filename);
  388. a.prepend(loading);
  389. a.prepend(img);
  390. li.append(a);
  391. // append the new app as last item in the list
  392. // which is the "add apps" entry with the id
  393. // #apps-management
  394. $('#apps-management').before(li);
  395. // scroll the app navigation down
  396. // so the newly added app is seen
  397. $('#navigation').animate({
  398. scrollTop: $('#navigation').height()
  399. }, 'slow');
  400. // draw attention to the newly added app entry
  401. // by flashing it twice
  402. $('#header .menutoggle')
  403. .animate({opacity: 0.5})
  404. .animate({opacity: 1})
  405. .animate({opacity: 0.5})
  406. .animate({opacity: 1})
  407. .animate({opacity: 0.75});
  408. }
  409. }
  410. container.children('li[data-id]').each(function(index, el) {
  411. if (!idsToKeep[$(el).data('id')]) {
  412. $(el).remove();
  413. }
  414. });
  415. }
  416. });
  417. },
  418. showErrorMessage: function(appId, message) {
  419. $('div#app-'+appId+' .warning')
  420. .show()
  421. .text(message);
  422. },
  423. hideErrorMessage: function(appId) {
  424. $('div#app-'+appId+' .warning')
  425. .hide()
  426. .text('');
  427. },
  428. showReloadMessage: function() {
  429. OC.dialogs.info(
  430. t(
  431. 'settings',
  432. 'The app has been enabled but needs to be updated. You will be redirected to the update page in 5 seconds.'
  433. ),
  434. t('settings','App update'),
  435. function () {
  436. window.location.reload();
  437. },
  438. true
  439. );
  440. },
  441. filter: function(query) {
  442. var $appList = $('#apps-list'),
  443. $emptyList = $('#apps-list-empty');
  444. $appList.removeClass('hidden');
  445. $appList.find('.section').removeClass('hidden');
  446. $emptyList.addClass('hidden');
  447. if (query === '') {
  448. return;
  449. }
  450. query = query.toLowerCase();
  451. $appList.find('.section').addClass('hidden');
  452. // App Name
  453. var apps = _.filter(OC.Settings.Apps.State.apps, function (app) {
  454. return app.name.toLowerCase().indexOf(query) !== -1;
  455. });
  456. // App ID
  457. apps = apps.concat(_.filter(OC.Settings.Apps.State.apps, function (app) {
  458. return app.id.toLowerCase().indexOf(query) !== -1;
  459. }));
  460. // App Description
  461. apps = apps.concat(_.filter(OC.Settings.Apps.State.apps, function (app) {
  462. return app.description.toLowerCase().indexOf(query) !== -1;
  463. }));
  464. // Author Name
  465. apps = apps.concat(_.filter(OC.Settings.Apps.State.apps, function (app) {
  466. return app.author.toLowerCase().indexOf(query) !== -1;
  467. }));
  468. // App status
  469. if (t('settings', 'Official').toLowerCase().indexOf(query) !== -1) {
  470. apps = apps.concat(_.filter(OC.Settings.Apps.State.apps, function (app) {
  471. return app.level === 200;
  472. }));
  473. }
  474. if (t('settings', 'Approved').toLowerCase().indexOf(query) !== -1) {
  475. apps = apps.concat(_.filter(OC.Settings.Apps.State.apps, function (app) {
  476. return app.level === 100;
  477. }));
  478. }
  479. if (t('settings', 'Experimental').toLowerCase().indexOf(query) !== -1) {
  480. apps = apps.concat(_.filter(OC.Settings.Apps.State.apps, function (app) {
  481. return app.level !== 100 && app.level !== 200;
  482. }));
  483. }
  484. apps = _.uniq(apps, function(app){return app.id;});
  485. if (apps.length === 0) {
  486. $appList.addClass('hidden');
  487. $emptyList.removeClass('hidden');
  488. $emptyList.removeClass('hidden').find('h2').text(t('settings', 'No apps found for {query}', {
  489. query: query
  490. }));
  491. } else {
  492. _.each(apps, function (app) {
  493. $('#app-' + app.id).removeClass('hidden');
  494. });
  495. $('#searchresults').hide();
  496. }
  497. },
  498. _onPopState: function(params) {
  499. params = _.extend({
  500. category: 'enabled'
  501. }, params);
  502. OC.Settings.Apps.loadCategory(params.category);
  503. },
  504. /**
  505. * Initializes the apps list
  506. */
  507. initialize: function($el) {
  508. OC.Plugins.register('OCA.Search', OC.Settings.Apps.Search);
  509. OC.Settings.Apps.loadCategories();
  510. OC.Util.History.addOnPopStateHandler(_.bind(this._onPopState, this));
  511. $(document).on('click', 'ul#apps-categories li', function () {
  512. var categoryId = $(this).data('categoryId');
  513. OC.Settings.Apps.loadCategory(categoryId);
  514. OC.Util.History.pushState({
  515. category: categoryId
  516. });
  517. $('#searchbox').val('');
  518. });
  519. $(document).on('click', '.app-description-toggle-show', function () {
  520. $(this).addClass('hidden');
  521. $(this).siblings('.app-description-toggle-hide').removeClass('hidden');
  522. $(this).siblings('.app-description-container').slideDown();
  523. });
  524. $(document).on('click', '.app-description-toggle-hide', function () {
  525. $(this).addClass('hidden');
  526. $(this).siblings('.app-description-toggle-show').removeClass('hidden');
  527. $(this).siblings('.app-description-container').slideUp();
  528. });
  529. $(document).on('click', '#apps-list input.enable', function () {
  530. var appId = $(this).data('appid');
  531. var element = $(this);
  532. var active = $(this).data('active');
  533. OC.Settings.Apps.enableApp(appId, active, element);
  534. });
  535. $(document).on('click', '#apps-list input.uninstall', function () {
  536. var appId = $(this).data('appid');
  537. var element = $(this);
  538. OC.Settings.Apps.uninstallApp(appId, element);
  539. });
  540. $(document).on('click', '#apps-list input.update', function () {
  541. var appId = $(this).data('appid');
  542. var element = $(this);
  543. OC.Settings.Apps.updateApp(appId, element);
  544. });
  545. $(document).on('change', '#group_select', function() {
  546. var element = $(this).parent().find('input.enable');
  547. var groups = $(this).val();
  548. if (groups && groups !== '') {
  549. groups = groups.split('|');
  550. } else {
  551. groups = [];
  552. }
  553. var appId = element.data('appid');
  554. if (appId) {
  555. OC.Settings.Apps.enableApp(appId, false, element, groups);
  556. OC.Settings.Apps.State.apps[appId].groups = groups;
  557. }
  558. });
  559. $(document).on('change', ".groups-enable__checkbox", function() {
  560. var $select = $(this).closest('.section').find('#group_select');
  561. $select.val('');
  562. if (this.checked) {
  563. OC.Settings.Apps.setupGroupsSelect($select);
  564. } else {
  565. $select.select2('destroy');
  566. }
  567. $select.change();
  568. });
  569. $(document).on('click', '#enable-experimental-apps', function () {
  570. var state = $(this).prop('checked');
  571. $.ajax(OC.generateUrl('settings/apps/experimental'), {
  572. data: {state: state},
  573. type: 'POST',
  574. success:function () {
  575. location.reload();
  576. }
  577. });
  578. });
  579. }
  580. };
  581. OC.Settings.Apps.Search = {
  582. attach: function (search) {
  583. search.setFilter('settings', OC.Settings.Apps.filter);
  584. }
  585. };
  586. $(document).ready(function () {
  587. // HACK: FIXME: use plugin approach
  588. if (!window.TESTING) {
  589. OC.Settings.Apps.initialize($('#apps-list'));
  590. }
  591. });