edit_dataset_view.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. App.MainMirroringEditDataSetView = Em.View.extend({
  20. name: 'mainMirroringEditDataSetView',
  21. templateName: require('templates/main/mirroring/edit_dataset'),
  22. /**
  23. * Defines if there are some target clusters defined
  24. * @type {Boolean}
  25. */
  26. hasTargetClusters: false,
  27. targetClusters: App.TargetCluster.find(),
  28. targetClusterSelect: Em.Select.extend({
  29. classNames: ['target-cluster-select'],
  30. content: function () {
  31. if (!this.get('parentView.isLoaded')) return [];
  32. return this.get('parentView.targetClusters').mapProperty('name').without(App.get('clusterName')).concat(Em.I18n.t('mirroring.dataset.addTargetCluster'));
  33. }.property('parentView.isLoaded', 'parentView.targetClusters.length'),
  34. change: function () {
  35. if (this.get('selection') === Em.I18n.t('mirroring.dataset.addTargetCluster')) {
  36. this.set('selection', this.get('content')[0]);
  37. this.get('parentView').manageClusters();
  38. }
  39. this.set('parentView.controller.formFields.datasetTargetClusterName', this.get('selection'))
  40. }
  41. }),
  42. /**
  43. * Set <code>hasTargetClusters</code> after clustes load
  44. */
  45. onTargetClustersChange: function () {
  46. if (this.get('isLoaded') && this.get('targetClusters.length') > 1) {
  47. this.set('hasTargetClusters', true);
  48. } else {
  49. this.set('hasTargetClusters', false);
  50. this.set('controller.formFields.datasetTargetClusterName', null);
  51. }
  52. }.observes('isLoaded', 'targetClusters.length'),
  53. repeatOptions: [Em.I18n.t('mirroring.dataset.repeat.minutes'), Em.I18n.t('mirroring.dataset.repeat.hours'), Em.I18n.t('mirroring.dataset.repeat.days'), Em.I18n.t('mirroring.dataset.repeat.months')],
  54. middayPeriodOptions: [Em.I18n.t('mirroring.dataset.middayPeriod.am'), Em.I18n.t('mirroring.dataset.middayPeriod.pm')],
  55. hourOptions: ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'],
  56. minuteOptions: ['00', '05', '10', '15', '20', '25', '30', '35', '40', '45', '50', '55'],
  57. isLoaded: function () {
  58. return App.router.get('mainMirroringController.isLoaded');
  59. }.property('App.router.mainMirroringController.isLoaded'),
  60. manageClusters: function () {
  61. App.router.get('mainMirroringController').manageClusters();
  62. },
  63. /**
  64. * Fill form input fields for selected dataset to edit
  65. */
  66. fillForm: function () {
  67. var isEdit = this.get('controller.isEdit');
  68. if (this.get('isLoaded') && isEdit) {
  69. var controller = this.get('controller');
  70. var dataset = App.Dataset.find().findProperty('id', controller.get('datasetIdToEdit'));
  71. var scheduleStartDate = new Date(dataset.get('scheduleStartDate'));
  72. var scheduleEndDate = new Date(dataset.get('scheduleEndDate'));
  73. var formFields = controller.get('formFields');
  74. formFields.set('datasetName', dataset.get('name'));
  75. formFields.set('datasetSourceDir', dataset.get('sourceDir'));
  76. formFields.set('datasetTargetDir', dataset.get('targetDir'));
  77. formFields.set('datasetTargetClusterName', dataset.get('targetClusterName'));
  78. formFields.set('datasetFrequency', dataset.get('frequency'));
  79. formFields.set('repeatOptionSelected', dataset.get('frequencyUnit'));
  80. formFields.set('datasetStartDate', controller.addZero(scheduleStartDate.getMonth() + 1) + '/' + controller.addZero(scheduleStartDate.getDate()) + '/' + controller.addZero(scheduleStartDate.getFullYear()));
  81. formFields.set('datasetEndDate', controller.addZero(scheduleEndDate.getMonth() + 1) + '/' + controller.addZero(scheduleEndDate.getDate()) + '/' + controller.addZero(scheduleEndDate.getFullYear()));
  82. var startHours = scheduleStartDate.getHours();
  83. var endHours = scheduleEndDate.getHours();
  84. formFields.set('hoursForStart', controller.toAMPMHours(startHours));
  85. formFields.set('hoursForEnd', controller.toAMPMHours(endHours));
  86. formFields.set('minutesForStart', controller.addZero(scheduleStartDate.getMinutes()));
  87. formFields.set('minutesForEnd', controller.addZero(scheduleEndDate.getMinutes()));
  88. formFields.set('middayPeriodForStart', startHours > 11 ? 'PM' : 'AM');
  89. formFields.set('middayPeriodForEnd', endHours > 11 ? 'PM' : 'AM');
  90. }
  91. }.observes('isLoaded', 'App.router.mainMirroringController.selectedDataset', 'controller.isEdit'),
  92. select: Em.Select.extend({
  93. attributeBindings: ['disabled']
  94. }),
  95. didInsertElement: function () {
  96. // Initialize datepicker
  97. $('.datepicker').datepicker({
  98. format: 'mm/dd/yyyy'
  99. }).on('changeDate', function (ev) {
  100. $(this).datepicker('hide');
  101. });
  102. // Set default value for Repeat every combo box
  103. this.set('controller.formFields.repeatOptionSelected', this.get('repeatOptions')[2]);
  104. this.fillForm();
  105. this.onTargetClustersChange();
  106. },
  107. willDestroyElement: function () {
  108. var controller = this.get('controller');
  109. Em.keys(this.get('controller.formFields')).forEach(function (key) {
  110. controller.removeObserver('formFields.' + key, controller, 'validate');
  111. }, this);
  112. this._super();
  113. },
  114. init: function () {
  115. this.get('controller').clearStep();
  116. this._super();
  117. }
  118. });