save_as_modal.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. ///<reference path="../../headers/common.d.ts" />
  2. import coreModule from 'app/core/core_module';
  3. const template = `
  4. <div class="modal-body modal-body--with-overflow">
  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 class="gf-form">
  21. <folder-picker ng-if="!clone.meta.isFolder" selected-folder="clone.meta.parentId" on-change="onFolderChange"></folder-picker>
  22. </div>
  23. </div>
  24. <div class="gf-form-button-row text-center">
  25. <button type="submit" class="btn btn-success" ng-disabled="ctrl.saveForm.$invalid">Save</button>
  26. <a class="btn-text" ng-click="ctrl.dismiss();">Cancel</a>
  27. </div>
  28. </form>
  29. </div>
  30. `;
  31. export class SaveDashboardAsModalCtrl {
  32. clone: any;
  33. dismiss: () => void;
  34. /** @ngInject */
  35. constructor(private $scope, private dashboardSrv) {
  36. var dashboard = this.dashboardSrv.getCurrent();
  37. this.clone = dashboard.getSaveModelClone();
  38. this.clone.id = null;
  39. this.clone.title += ' Copy';
  40. this.clone.editable = true;
  41. this.clone.hideControls = false;
  42. // remove alerts
  43. this.clone.rows.forEach(row => {
  44. row.panels.forEach(panel => {
  45. delete panel.alert;
  46. });
  47. });
  48. delete this.clone.autoUpdate;
  49. }
  50. save() {
  51. return this.dashboardSrv.save(this.clone).then(this.dismiss);
  52. }
  53. keyDown(evt) {
  54. if (evt.keyCode === 13) {
  55. this.save();
  56. }
  57. }
  58. onFolderChange(parentId) {
  59. this.clone.parentId = parentId;
  60. }
  61. }
  62. export function saveDashboardAsDirective() {
  63. return {
  64. restrict: 'E',
  65. template: template,
  66. controller: SaveDashboardAsModalCtrl,
  67. bindToController: true,
  68. controllerAs: 'ctrl',
  69. scope: {dismiss: "&"}
  70. };
  71. }
  72. coreModule.directive('saveDashboardAsModal', saveDashboardAsDirective);