filesystemtagsplugin.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. (function() {
  21. OCA.WorkflowEngine = OCA.WorkflowEngine || {};
  22. OCA.WorkflowEngine.Plugins = OCA.WorkflowEngine.Plugins || {};
  23. OCA.WorkflowEngine.Plugins.FileSystemTagsPlugin = {
  24. getCheck: function() {
  25. this.collection = OC.SystemTags.collection;
  26. return {
  27. 'class': 'OCA\\WorkflowEngine\\Check\\FileSystemTags',
  28. 'name': t('workflowengine', 'File system tag'),
  29. 'operators': [
  30. {'operator': 'is', 'name': t('workflowengine', 'is tagged with')},
  31. {'operator': '!is', 'name': t('workflowengine', 'is not tagged with')}
  32. ]
  33. };
  34. },
  35. render: function(element, check) {
  36. if (check['class'] !== 'OCA\\WorkflowEngine\\Check\\FileSystemTags') {
  37. return;
  38. }
  39. $(element).css('width', '400px');
  40. $(element).select2({
  41. allowClear: false,
  42. multiple: false,
  43. placeholder: t('workflowengine', 'Select tag…'),
  44. query: _.debounce(function(query) {
  45. query.callback({
  46. results: OC.SystemTags.collection.filterByName(query.term)
  47. });
  48. }, 100, true),
  49. id: function(element) {
  50. return element.get('id');
  51. },
  52. initSelection: function(element, callback) {
  53. callback($(element).val());
  54. },
  55. formatResult: function (tag) {
  56. return OC.SystemTags.getDescriptiveTag(tag);
  57. },
  58. formatSelection: function (tagId) {
  59. var tag = OC.SystemTags.collection.get(tagId);
  60. if (!_.isUndefined(tag)) {
  61. return OC.SystemTags.getDescriptiveTag(tag);
  62. }
  63. },
  64. escapeMarkup: function(m) {
  65. return m;
  66. }
  67. });
  68. }
  69. };
  70. })();
  71. OC.Plugins.register('OCA.WorkflowEngine.CheckPlugins', OCA.WorkflowEngine.Plugins.FileSystemTagsPlugin);