/*! grafana - v3.0.4 - 2016-06-01
 * Copyright (c) 2016 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",title:"Settings"},annotations:{src:"public/app/features/annotations/partials/editor.html",title:"Annotations"},templating:{src:"public/app/features/templating/partials/editor.html",title:"Templating"}};b["default"].directive("dashEditorLink",["$timeout",function(a){return{restrict:"A",link:function(b,c,d){var e=d.dashEditorLink;c.bind("click",function(){a(function(){var a="isolated"===d.editorScope?null:b;b.appEvent("show-dash-editor",{src:e,scope:a})})})}}}]),b["default"].directive("dashEditorView",["$compile","$location",function(b,d){return{restrict:"A",link:function(e,f){function g(){i&&(e.appEvent("dash-editor-hidden",j),i.dismiss())}function h(h,k,l){if(l&&(e.contextSrv.editview=c[l],k.src=e.contextSrv.editview.src),j===k.src)return void g();g(),j=k.src,i=k.scope?k.scope.$new():e.$new(),i.dismiss=function(){if(i.$destroy(),f.empty(),j=null,i=null,l){var a=d.search();l===a.editview&&(delete a.editview,d.search(a))}};var m="'"+k.src+"'",n=a('<div class="tabbed-view" ng-include="'+m+'"></div>');f.append(n),b(f.contents())(i)}var i,j;e.$watch("dashboardViewState.state.editview",function(a,b){a?h(null,{},a):b&&(e.contextSrv.editview=null,j===c[b]&&g())}),e.contextSrv.editview=null,e.$on("$destroy",g),e.onAppEvent("hide-dash-editor",g),e.onAppEvent("show-dash-editor",h)}}}])});