save_as_modal.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 $scope, 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
  40. this.clone.rows.forEach(row => {
  41. row.panels.forEach(panel => {
  42. delete panel.alert;
  43. });
  44. });
  45. delete this.clone.autoUpdate;
  46. }
  47. save() {
  48. return this.dashboardSrv.save(this.clone).then(this.dismiss);
  49. }
  50. keyDown(evt) {
  51. if (evt.keyCode === 13) {
  52. this.save();
  53. }
  54. }
  55. }
  56. export function saveDashboardAsDirective() {
  57. return {
  58. restrict: 'E',
  59. template: template,
  60. controller: SaveDashboardAsModalCtrl,
  61. bindToController: true,
  62. controllerAs: 'ctrl',
  63. scope: {dismiss: "&"}
  64. };
  65. }
  66. coreModule.directive('saveDashboardAsModal', saveDashboardAsDirective);