save_as_modal.ts 2.3 KB

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