D_Pain

Search2

Aug 2nd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. exports.id = 'search';
  2. exports.title = 'Searcher';
  3. exports.group = 'Common';
  4. exports.color = '#2ec9e2';
  5. exports.input = 1;
  6. exports.output = 1;
  7. exports.author = 'DPain';
  8. exports.icon = 'tasks';
  9. exports.version = '0.0.1';
  10. exports.options = {
  11. name: '',
  12. age: '',
  13. height: '',
  14. hobby: ''
  15. };
  16.  
  17. exports.html = `<div data-scope="?__init:scopeinit">
  18. <div class="padding">
  19. <div class="row">
  20. <div class="col-md-6 m">
  21. <div data---="input__?.name__required:1;placeholder:Search or Create a Name;dirsource:name_list;dircustom:true;$setter:request_preset">@(Name)</div>
  22. </div>
  23. <div class="col-md-6 m">
  24. <div data---="textbox__?.age__type:string">@(Age)</b></div>
  25. </div>
  26. </div>
  27. <div class="row">
  28. <div class="col-md-12 m">
  29. <div data---="textbox__?.height__type:string">@(Height)</div>
  30. </div>
  31. </div>
  32. <div class="row">
  33. <div class="col-md-12 m">
  34. <div data---="textbox__?.hobby__type:string">@(Hobby)</div>
  35. </div>
  36. </div>
  37. </div>
  38. </div>
  39. <script>
  40. name_list = ['Andy', 'Bob', 'Candy'];
  41. presets = [
  42. {
  43. name: 'Andy',
  44. age: '20',
  45. height: '180cm',
  46. hobby: 'Bowling'
  47. }, {
  48. name: 'Bob',
  49. age: '30',
  50. height: '185cm',
  51. hobby: 'Movies'
  52. }, {
  53. name: 'Candy',
  54. age: '18',
  55. height: '160cm',
  56. hobby: 'Video Games'
  57. }
  58. ];
  59.  
  60. /*
  61. Scope for this component.
  62. */
  63. scope = null;
  64. function scopeinit(path, el) {
  65. scope = el.scope();
  66. console.log(scope.id);
  67. console.log(scope.path);
  68. }
  69. // ----- //
  70.  
  71. old_value = null;
  72.  
  73. function request_preset(value) {
  74. // Value is not empty.
  75. if (value != null) {
  76. // Value is different.
  77. if (value != old_value) {
  78. old_value = value;
  79. if (name_list.includes(value)) {
  80. console.log('Selected value is not a custom value!');
  81. let obj = null;
  82. presets.forEach(function(element) {
  83. if(element.name == value) {
  84. obj = element;
  85. }
  86. });
  87.  
  88. if(obj != null) {
  89. Object.keys(obj).forEach(function(key) {
  90. console.log(key);
  91. scope.set(key, obj[key]);
  92. });
  93. }
  94. }
  95. }
  96. }
  97. }
  98.  
  99. ON('save.search', function(component, options) {
  100. // Reassigning values to options.
  101. Object.keys(options).forEach(function(key) {
  102. let val = scope.get(key);
  103. if (val != null) {
  104. options[key] = val;
  105. }
  106. });
  107. });
  108. </script>`
  109.  
  110. exports.readme = `# Test`
  111.  
  112. exports.install = function (instance) {
  113.  
  114. instance.on('data', function (response) {
  115. console.log(response);
  116. });
  117. };
Add Comment
Please, Sign In to add comment