hive-action.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. import Ember from 'ember';
  18. import EmberValidations from 'ember-validations';
  19. export default Ember.Component.extend(EmberValidations,{
  20. hiveOptionObserver : Ember.observer('isScript',function(){
  21. if(this.get('isScript')){
  22. this.set("actionModel.query", undefined);
  23. }else{
  24. this.set("actionModel.script", undefined);
  25. }
  26. }),
  27. setUp : function(){
  28. if(this.get('actionModel.script')){
  29. this.set('isScript', true);
  30. }else if(this.get('actionModel.query')){
  31. this.set('isScript', false);
  32. }else{
  33. this.set('isScript', true);
  34. }
  35. if(this.get('actionModel.jobXml') === undefined){
  36. this.set("actionModel.jobXml", Ember.A([]));
  37. }
  38. if(this.get('actionModel.args') === undefined){
  39. this.set("actionModel.args", Ember.A([]));
  40. }
  41. if(this.get('actionModel.params') === undefined){
  42. this.set("actionModel.params", Ember.A([]));
  43. }
  44. if(this.get('actionModel.files') === undefined){
  45. this.set("actionModel.files", Ember.A([]));
  46. }
  47. if(this.get('actionModel.archives') === undefined){
  48. this.set("actionModel.archives", Ember.A([]));
  49. }
  50. if(this.get('actionModel.prepare') === undefined){
  51. this.set("actionModel.prepare", Ember.A([]));
  52. }
  53. if(this.get('actionModel.configuration') === undefined){
  54. this.set("actionModel.configuration",{});
  55. this.set("actionModel.configuration.property", Ember.A([]));
  56. }
  57. }.on('init'),
  58. initialize : function(){
  59. this.sendAction('register','hiveAction', this);
  60. this.on('fileSelected',function(fileName){
  61. this.set(this.get('filePathModel'), fileName);
  62. }.bind(this));
  63. }.on('didInsertElement'),
  64. observeError :function(){
  65. if(this.$('#collapseOne label.text-danger').length > 0 && !this.$('#collapseOne').hasClass("in")){
  66. this.$('#collapseOne').collapse('show');
  67. }
  68. }.on('didUpdate'),
  69. validations : {
  70. 'actionModel.script': {
  71. presence: {
  72. 'if':'isScript',
  73. 'message' : 'You need to provide a value for Script'
  74. }
  75. },
  76. 'actionModel.query': {
  77. presence: {
  78. unless :'isScript',
  79. 'message' : 'You need to provide a value for Query'
  80. }
  81. }
  82. },
  83. actions : {
  84. openFileBrowser(model, context){
  85. if(undefined === context){
  86. context = this;
  87. }
  88. this.set('filePathModel', model);
  89. this.sendAction('openFileBrowser', model, context);
  90. },
  91. register (name, context){
  92. this.sendAction('register',name , context);
  93. },
  94. onHiveOptionChange(value){
  95. if(value === "script"){
  96. this.set('isScript',true);
  97. }else{
  98. this.set('isScript',false);
  99. }
  100. }
  101. }
  102. });