save_as_modal.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. ///<reference path="../../headers/common.d.ts" />
  2. import coreModule from 'app/core/core_module';
  3. const template = `
  4. <div class="modal-body">
  5. <div class="modal-header">
  6. <h2 class="modal-header-title">
  7. <i class="fa fa-copy"></i>
  8. <span class="p-l-1">Save As...</span>
  9. </h2>
  10. <a class="modal-header-close" ng-click="ctrl.dismiss();">
  11. <i class="fa fa-remove"></i>
  12. </a>
  13. </div>
  14. <form name="ctrl.saveForm" ng-submit="ctrl.save()" class="modal-content" novalidate>
  15. <div class="p-t-2">
  16. <div class="gf-form">
  17. <label class="gf-form-label">New name</label>
  18. <input type="text" class="gf-form-input" ng-model="ctrl.clone.title" give-focus="true" required>
  19. </div>
  20. </div>
  21. <div class="gf-form-button-row text-center">
  22. <button type="submit" class="btn btn-success" ng-disabled="ctrl.saveForm.$invalid">Save</button>
  23. <a class="btn-text" ng-click="ctrl.dismiss();">Cancel</a>
  24. </div>
  25. </form>
  26. </div>
  27. `;
  28. export class SaveDashboardAsModalCtrl {
  29. clone: any;
  30. dismiss: () => void;
  31. /** @ngInject */
  32. constructor(private dashboardSrv) {
  33. var dashboard = this.dashboardSrv.getCurrent();
  34. this.clone = dashboard.getSaveModelClone();
  35. this.clone.id = null;
  36. this.clone.title += ' Copy';
  37. this.clone.editable = true;
  38. this.clone.hideControls = false;
  39. // remove alerts if source dashboard is already persisted
  40. // do not want to create alert dupes
  41. if (dashboard.id > 0) {
  42. this.clone.rows.forEach(row => {
  43. row.panels.forEach(panel => {
  44. delete panel.thresholds;
  45. delete panel.alert;
  46. });
  47. });
  48. }
  49. delete this.clone.autoUpdate;
  50. }
  51. save() {
  52. return this.dashboardSrv.save(this.clone).then(this.dismiss);
  53. }
  54. keyDown(evt) {
  55. if (evt.keyCode === 13) {
  56. this.save();
  57. }
  58. }
  59. }
  60. export function saveDashboardAsDirective() {
  61. return {
  62. restrict: 'E',
  63. template: template,
  64. controller: SaveDashboardAsModalCtrl,
  65. bindToController: true,
  66. controllerAs: 'ctrl',
  67. scope: {dismiss: "&"}
  68. };
  69. }
  70. coreModule.directive('saveDashboardAsModal', saveDashboardAsDirective);