edit_dataset_view.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. var filters = require('views/common/filter_view');
  20. var sort = require('views/common/sort_view');
  21. var date = require('utils/date');
  22. App.MainMirroringEditDataSetView = Em.View.extend({
  23. name: 'mainMirroringEditDataSetView',
  24. templateName: require('templates/main/mirroring/edit_dataset'),
  25. hasTargetClusters: false,
  26. targetClusters: App.TargetCluster.find(),
  27. targetClusterSelect: Em.Select.extend({
  28. classNames: ['target-cluster-select'],
  29. content: function () {
  30. if (!this.get('parentView.isLoaded')) return [];
  31. return this.get('parentView.targetClusters').mapProperty('name').without(App.get('clusterName')).concat(Em.I18n.t('mirroring.dataset.addTargetCluster'));
  32. }.property('parentView.isLoaded', 'parentView.targetClusters.length'),
  33. change: function () {
  34. if (this.get('selection') === Em.I18n.t('mirroring.dataset.addTargetCluster')) {
  35. this.set('selection', this.get('content')[0]);
  36. this.get('parentView').manageClusters();
  37. }
  38. this.set('parentView.controller.formFields.datasetTargetClusterName', this.get('selection'))
  39. }
  40. }),
  41. onTargetClustersChange: function () {
  42. if (this.get('isLoaded') && this.get('targetClusters.length') > 1) {
  43. this.set('hasTargetClusters', true);
  44. } else {
  45. this.set('hasTargetClusters', false);
  46. this.set('controller.formFields.datasetTargetClusterName', null);
  47. }
  48. }.observes('isLoaded', 'targetClusters.length'),
  49. 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')],
  50. middayPeriodOptions: [Em.I18n.t('mirroring.dataset.middayPeriod.am'), Em.I18n.t('mirroring.dataset.middayPeriod.pm')],
  51. hourOptions: ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'],
  52. minuteOptions: ['00', '05', '10', '15', '20', '25', '30', '35', '40', '45', '50', '55'],
  53. isLoaded: function () {
  54. return App.router.get('mainMirroringController.isLoaded');
  55. }.property('App.router.mainMirroringController.isLoaded'),
  56. manageClusters: function () {
  57. App.router.get('mainMirroringController').manageClusters();
  58. },
  59. fillForm: function () {
  60. var isEdit = this.get('controller.isEdit');
  61. var selectedDataset = App.router.get('mainMirroringController.selectedDataset');
  62. if (this.get('isLoaded') && selectedDataset && isEdit) {
  63. var controller = this.get('controller');
  64. var dataset = App.Dataset.find().findProperty('name', selectedDataset.get('id'));
  65. var scheduleStartDate = new Date(dataset.get('scheduleStartDate'));
  66. var scheduleEndDate = new Date(dataset.get('scheduleEndDate'));
  67. var formFields = controller.get('formFields');
  68. formFields.set('datasetName', dataset.get('name'));
  69. formFields.set('datasetSourceDir', dataset.get('sourceDir'));
  70. formFields.set('datasetTargetDir', dataset.get('targetDir'));
  71. formFields.set('datasetTargetClusterName', dataset.get('targetClusterName'));
  72. formFields.set('datasetFrequency', dataset.get('frequency'));
  73. formFields.set('repeatOptionSelected', dataset.get('frequencyUnit'));
  74. formFields.set('datasetStartDate', controller.addZero(scheduleStartDate.getMonth() + 1) + '/' + controller.addZero(scheduleStartDate.getDate()) + '/' + controller.addZero(scheduleStartDate.getFullYear()));
  75. formFields.set('datasetEndDate', controller.addZero(scheduleEndDate.getMonth() + 1) + '/' + controller.addZero(scheduleEndDate.getDate()) + '/' + controller.addZero(scheduleEndDate.getFullYear()));
  76. var startHours = scheduleStartDate.getHours();
  77. var endHours = scheduleEndDate.getHours();
  78. formFields.set('hoursForStart', controller.toAMPMHours(startHours));
  79. formFields.set('hoursForEnd', controller.toAMPMHours(endHours));
  80. formFields.set('minutesForStart', controller.addZero(scheduleStartDate.getMinutes()));
  81. formFields.set('minutesForEnd', controller.addZero(scheduleEndDate.getMinutes()));
  82. formFields.set('middayPeriodForStart', startHours > 11 ? 'PM' : 'AM');
  83. formFields.set('middayPeriodForEnd', endHours > 11 ? 'PM' : 'AM');
  84. }
  85. }.observes('isLoaded', 'App.router.mainMirroringController.selectedDataset', 'controller.isEdit'),
  86. select: Em.Select.extend({
  87. attributeBindings: ['disabled']
  88. }),
  89. didInsertElement: function () {
  90. // Initialize datepicker
  91. $('.datepicker').datepicker({
  92. format: 'mm/dd/yyyy'
  93. }).on('changeDate', function (ev) {
  94. $(this).datepicker('hide');
  95. });
  96. // Set default value for Repeat every combo box
  97. this.set('controller.formFields.repeatOptionSelected', this.get('repeatOptions')[2]);
  98. this.fillForm();
  99. this.onTargetClustersChange();
  100. },
  101. willDestroyElement: function () {
  102. var controller = this.get('controller');
  103. Em.keys(this.get('controller.formFields')).forEach(function (key) {
  104. controller.removeObserver('formFields.' + key, controller, 'validate');
  105. }, this);
  106. this._super();
  107. },
  108. init: function () {
  109. this.get('controller').clearStep();
  110. this._super();
  111. }
  112. });