apps.js 22 KB

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