angular.module("widgetkit").controller("k2Ctrl",["$scope","Application","$http","$filter",function(e){var i=this,n=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}],n.mapping=n.mapping?n.mapping:{},n.fields=n.fields?default_fields.concat(n.fields):default_fields;var a=[];n.fields=n.fields.filter(function(e){return-1==a.indexOf(e.id)?(a.push(e.id),!0):!1});try{e.k2=JSON.parse(angular.element('script[type="k2/config"]')[0].innerHTML)}catch(d){e.k2={}}e.$watch("content.data.fields",function(){angular.forEach(e.k2.fields,function(e,i){angular.forEach(n.fields,function(a){if(n.mapping[i]=n.mapping[i]?n.mapping[i]:{},void 0==n.mapping[i][a.id]){var d=e.filter(function(e){return e.id==a.def});n.mapping[i][a.id]=d.length?d[0].id:"none"}})})}),i.addField=function(){var e=angular.element("#k2-field-new")[0];e.value.length&&(n.fields.push({id:e.value,name:e.value}),e.value="")},i.deleteField=function(e){n.fields.splice(n.fields.indexOf(e),1)}}]);