dataset_controller.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. App.MainMirroringDataSetController = Ember.Controller.extend({
  19. name: 'mainMirroringDataSetController',
  20. model: Ember.Object.create(
  21. {
  22. newDataSet: null,
  23. listOfTargetClusterNames: function () {
  24. var listOfClusterNames = [];
  25. var listOfTargetClusters = App.TargetCluster.find();
  26. if (listOfTargetClusters && listOfTargetClusters.content.length) {
  27. listOfTargetClusters.forEach(function (tcluster) {
  28. listOfClusterNames.push(tcluster.get('clusterName'));
  29. });
  30. }
  31. return listOfClusterNames;
  32. }.property('newDataSet.targetCluster'), // this property will be set when someone clicks the save button
  33. originalRecord: null
  34. }
  35. ),
  36. /**
  37. * Popup with add/edit form
  38. */
  39. popup: null,
  40. /**
  41. * true - popup with edit form
  42. * false - popup with add form
  43. */
  44. isPopupForEdit: false,
  45. createNewDataSet: function () {
  46. var newDataSet = Ember.Object.create({
  47. name: null,
  48. sourceDir: null,
  49. targetCluster: Ember.Object.create(),
  50. targetDir: null,
  51. schedule: Ember.Object.create()
  52. });
  53. this.set('model.newDataSet', newDataSet);
  54. return newDataSet;
  55. },
  56. setDataSet: function (dataset) {
  57. var newDataSet = Ember.Object.create({
  58. name: dataset.get('name'),
  59. sourceDir: dataset.get('sourceDir'),
  60. targetCluster: dataset.get('targetCluster'),
  61. targetDir: dataset.get('targetDir'),
  62. schedule: dataset.get('schedule')
  63. });
  64. this.set('model.newDataSet', newDataSet);
  65. },
  66. setOriginalDataSetRecord: function (datasetRecord) {
  67. this.set('model.originalRecord', datasetRecord);
  68. },
  69. getNewDataSet: function () {
  70. return this.get('model.newDataSet');
  71. },
  72. createTargetCluster: function () {
  73. var controller = App.router.get('mainMirroringTargetClusterController');
  74. controller.set('returnRoute', App.get('router.currentState.path'));
  75. App.router.transitionTo('addTargetClusterRoute');
  76. },
  77. /**
  78. * Set old values for all properties in the dataset
  79. */
  80. undoChanges: function () {
  81. this.set('model.newDataSet', this.get('rawDataSet'));
  82. },
  83. /**
  84. * Delete created dataset and its schedule
  85. */
  86. deleteNewDataSet: function () {
  87. var originalRecordSchedule = this.get('model.originalRecord.schedule');
  88. originalRecordSchedule.deleteRecord();
  89. originalRecordSchedule.get("transaction").commit();
  90. var originalRecord = this.get('model.originalRecord');
  91. originalRecord.deleteRecord();
  92. originalRecord.get("transaction").commit();
  93. },
  94. /**
  95. * "Delete" button handler
  96. */
  97. deleteDatasetClick: function () {
  98. var self = this;
  99. App.showConfirmationPopup(function () {
  100. self.deleteNewDataSet();
  101. self.get('popup').hide();
  102. App.router.transitionTo('main.mirroring.index');
  103. });
  104. }
  105. });