angular.module("widgetkit").controller("zooCtrl",["$scope","Application","$http","$filter",function(e,i,a,n){var t=this,o=e.content.data,r=[{id:"content",name:"content",def:"textarea",core:!0},{id:"media",name:"media",def:"image",core:!0},{id:"link",name:"link",def:"itemlink",core:!0},{id:"date",name:"date",def:"itempublish_up",core:!0},{id:"author",name:"author",def:"itemauthor",core:!0},{id:"categories",name:"categories",def:"itemcategory",core:!0}];o.mapping=o.mapping?o.mapping:{},o.fields=o.fields?r.concat(o.fields):r;var d=[];o.fields=o.fields.filter(function(e){return d.indexOf(e.id)==-1&&(d.push(e.id),!0)});try{e.zoo=JSON.parse(angular.element('script[type="zoo/config"]')[0].innerHTML)}catch(p){e.zoo={}}e.order=[];var l=n("zoo")(n("toArray")(n("toArray")(e.zoo)[0].types)[0].elements,{core:!0,orderable:!0});l.push({id:"_alphanumeric",name:n("trans")("Alphanumeric")}),jQuery.each(l,function(i,a){var t=jQuery.extend({},a,{id:a.id+"_reversed",name:a.name+" "+n("trans")("Reversed")});e.order.push(a),e.order.push(t)}),e.order.push({id:"_random",name:n("trans")("Random")});var c=o.application;e.$watch("content.data.application",function(){if(o.application&&c!=o.application){var i=n("toArray")(e.zoo[o.application].categories)[0];o.category=i?i.id:"";var a=n("toArray")(e.zoo[o.application].types)[0];a&&(o.type=a.id),angular.forEach(e.zoo[o.application].types,function(e){angular.forEach(o.fields,function(i){if(o.mapping[e.id]=o.mapping[e.id]?o.mapping[e.id]:{},void 0==o.mapping[e.id][i.id]){var a=e.elements.filter(function(e){return e.type==i.def});a.length?o.mapping[e.id][i.id]=a[0].id:o.mapping[e.id][i.id]="none"}})})}}),e.$watch("content.data.mode",function(){angular.element('#zoo-mapping-types li[data-id="'+o.type+'"]').addClass("uk-active")}),t.addField=function(){var e=angular.element("#zoo-field-new")[0];e.value.length&&(o.fields.push({id:e.value,name:e.value}),e.value="")},t.deleteField=function(e){o.fields.splice(o.fields.indexOf(e),1)},UIkit.init()}]).filter("zoo",function(){return function(e,i){return e&&angular.forEach(i,function(i,a){e=e.filter(function(e){return e[a]==i})}),e}});