/*! grafana - v4.2.0 - 2017-03-24
 * Copyright (c) 2017 Torkel Ödegaard; Licensed Apache-2.0 */

define(["jquery","../core_module"],function(a,b){"use strict";var c={settings:{src:"public/app/features/dashboard/partials/settings.html"},annotations:{src:"public/app/features/annotations/partials/editor.html"},templating:{src:"public/app/features/templating/partials/editor.html"},import:{src:"<dash-import></dash-import>"}};b.default.directive("dashEditorView",["$compile","$location","$rootScope",function(b,d,e){return{restrict:"A",link:function(f,g){function h(){j&&(f.appEvent("dash-editor-hidden",k),j.dismiss())}function i(i,l,m){if(m&&(f.contextSrv.editview=c[m],l.src=f.contextSrv.editview.src),k===l.src)return void h();if(h(),k=l.src,j=l.scope?l.scope.$new():f.$new(),j.dismiss=function(){if(j.$destroy(),g.empty(),k=null,j=null,m){var a=d.search();m===a.editview&&(delete a.editview,d.search(a))}},"import"===m){var n=e.$new();return n.$on("$destroy",function(){j.dismiss()}),void e.appEvent("show-modal",{templateHtml:"<dash-import></dash-import>",scope:n,backdrop:"static"})}var o=l.src;o.indexOf(".html")>0&&(o=a('<div class="tabbed-view" ng-include="\''+o+"'\"></div>")),g.append(o),b(g.contents())(j)}var j,k;f.$watch("dashboardViewState.state.editview",function(a,b){a?i(null,{},a):b&&(f.contextSrv.editview=null,k===c[b]&&h())}),f.contextSrv.editview=null,f.$on("$destroy",h),f.onAppEvent("hide-dash-editor",h),f.onAppEvent("show-dash-editor",i)}}}])});