You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

filenameplugin.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * @copyright Copyright (c) 2018 Daniel Kesselberg <mail@danielkesselberg.de>
  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.FileNamePlugin = {
  24. getCheck: function () {
  25. return {
  26. 'class': 'OCA\\WorkflowEngine\\Check\\FileName',
  27. 'name': t('workflowengine', 'File name'),
  28. 'operators': [
  29. {'operator': 'is', 'name': t('workflowengine', 'is')},
  30. {'operator': '!is', 'name': t('workflowengine', 'is not')},
  31. {
  32. 'operator': 'matches',
  33. 'name': t('workflowengine', 'matches')
  34. },
  35. {
  36. 'operator': '!matches',
  37. 'name': t('workflowengine', 'does not match')
  38. }
  39. ]
  40. };
  41. },
  42. render: function (element, check) {
  43. if (check['class'] !== 'OCA\\WorkflowEngine\\Check\\FileName') {
  44. return;
  45. }
  46. var placeholder = 'dummy.jpg';
  47. if (check['operator'] === 'matches' || check['operator'] === '!matches') {
  48. placeholder = '/^dummy-.+$/i';
  49. if (this._validateRegex(check['value'])) {
  50. $(element).removeClass('invalid-input');
  51. } else {
  52. $(element).addClass('invalid-input');
  53. }
  54. }
  55. $(element).css('width', '250px')
  56. .attr('placeholder', placeholder)
  57. .attr('title', t('workflowengine', 'Example: {placeholder}', {placeholder: placeholder}))
  58. .addClass('has-tooltip')
  59. .tooltip({
  60. placement: 'bottom'
  61. });
  62. },
  63. _validateRegex: function (string) {
  64. var regexRegex = /^\/(.*)\/([gui]{0,3})$/,
  65. result = regexRegex.exec(string);
  66. return result !== null;
  67. }
  68. };
  69. })();
  70. OC.Plugins.register('OCA.WorkflowEngine.CheckPlugins', OCA.WorkflowEngine.Plugins.FileNamePlugin);