1
0

requesturlplugin.js 3.3 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. (function() {
  21. OCA.WorkflowEngine = OCA.WorkflowEngine || {};
  22. OCA.WorkflowEngine.Plugins = OCA.WorkflowEngine.Plugins || {};
  23. OCA.WorkflowEngine.Plugins.RequestURLPlugin = {
  24. predefinedValues: ['webdav'],
  25. getCheck: function() {
  26. return {
  27. 'class': 'OCA\\WorkflowEngine\\Check\\RequestURL',
  28. 'name': t('workflowengine', 'Request URL'),
  29. 'operators': [
  30. {'operator': 'is', 'name': t('workflowengine', 'is')},
  31. {'operator': '!is', 'name': t('workflowengine', 'is not')},
  32. {'operator': 'matches', 'name': t('workflowengine', 'matches')},
  33. {'operator': '!matches', 'name': t('workflowengine', 'does not match')}
  34. ]
  35. };
  36. },
  37. render: function(element, check) {
  38. if (check['class'] !== 'OCA\\WorkflowEngine\\Check\\RequestURL') {
  39. return;
  40. }
  41. var placeholder = 'https://localhost/index.php';
  42. if (check['operator'] === 'matches' || check['operator'] === '!matches') {
  43. placeholder = '/^https\\:\\/\\/localhost\\/index\\.php$/i';
  44. }
  45. $(element).css('width', '250px')
  46. .attr('placeholder', placeholder)
  47. .attr('title', t('workflowengine', 'Example: {placeholder}', {placeholder: placeholder}))
  48. .addClass('has-tooltip')
  49. .tooltip({
  50. placement: 'bottom'
  51. });
  52. if (check['operator'] === 'matches' || check['operator'] === '!matches') {
  53. if (this._validateRegex(check['value'])) {
  54. $(element).removeClass('invalid-input');
  55. } else {
  56. $(element).addClass('invalid-input');
  57. }
  58. } else {
  59. var self = this,
  60. data = [
  61. {
  62. text: t('workflowengine', 'Predefined URLs'),
  63. children: [
  64. {id: 'webdav', text: t('workflowengine', 'Files WebDAV')}
  65. ]
  66. }
  67. ];
  68. if (this.predefinedValues.indexOf(check['value']) === -1) {
  69. data.unshift({
  70. id: check['value'],
  71. text: check['value']
  72. })
  73. }
  74. $(element).select2({
  75. data: data,
  76. createSearchChoice: function(term) {
  77. if (self.predefinedValues.indexOf(check['value']) === -1) {
  78. return {
  79. id: term,
  80. text: term
  81. };
  82. }
  83. },
  84. id: function(element) {
  85. return element.id;
  86. },
  87. formatResult: function (tag) {
  88. return tag.text;
  89. },
  90. formatSelection: function (tag) {
  91. return tag.text;
  92. },
  93. escapeMarkup: function(m) {
  94. return m;
  95. }
  96. })
  97. }
  98. },
  99. _validateRegex: function(string) {
  100. var regexRegex = /^\/(.*)\/([gui]{0,3})$/,
  101. result = regexRegex.exec(string);
  102. return result !== null;
  103. }
  104. };
  105. })();
  106. OC.Plugins.register('OCA.WorkflowEngine.CheckPlugins', OCA.WorkflowEngine.Plugins.RequestURLPlugin);