angular.module("widgetkit").controller("k2Ctrl",["$scope","Application","$http","$filter",function(e,i,n,a){var d=this,t=e.content.data;default_fields=[{id:"content",name:"content",def:"full",core:!0},{id:"media",name:"media",def:"image",core:!0},{id:"date",name:"date",def:"publish_up",core:!0},{id:"author",name:"author",def:"author",core:!0},{id:"categories",name:"categories",def:"categories",core:!0},{id:"link",name:"link",def:"link",core:!0}],t.mapping=t.mapping?t.mapping:{},t.fields=t.fields?default_fields.concat(t.fields):default_fields;var l=[];t.fields=t.fields.filter(function(e){return l.indexOf(e.id)==-1&&(l.push(e.id),!0)});try{e.k2=JSON.parse(angular.element('script[type="k2/config"]')[0].innerHTML)}catch(f){e.k2={}}e.$watch("content.data.fields",function(){angular.forEach(e.k2.fields,function(e,i){angular.forEach(t.fields,function(n){if(i=i||"default",t.mapping[i]=t.mapping[i]?t.mapping[i]:{},void 0==t.mapping[i][n.id]){var a=e.filter(function(e){return e.id==n.def});a.length?t.mapping[i][n.id]=a[0].id:t.mapping[i][n.id]="none"}})})}),d.addField=function(){var e=angular.element("#k2-field-new")[0];e.value.length&&(t.fields.push({id:e.value,name:e.value}),e.value="")},d.deleteField=function(e){t.fields.splice(t.fields.indexOf(e),1)}}]);