angular.module("widgetkit").controller("zooCtrl",["$scope","Application","$http","$filter",function(e,a,i,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-1==d.indexOf(e.id)?(d.push(e.id),!0):!1});try{e.zoo=JSON.parse(angular.element('script[type="zoo/config"]')[0].innerHTML)}catch(l){e.zoo={}}e.order=[];var c=n("zoo")(n("toArray")(n("toArray")(e.zoo)[0].types)[0].elements,{core:!0,orderable:!0});c.push({id:"_alphanumeric",name:n("trans")("Alphanumeric")}),jQuery.each(c,function(a,i){var t=jQuery.extend({},i,{id:i.id+"_reversed",name:i.name+" "+n("trans")("Reversed")});e.order.push(i),e.order.push(t)}),e.order.push({id:"_random",name:n("trans")("Random")});var p=o.application;e.$watch("content.data.application",function(){if(o.application&&p!=o.application){var a=n("toArray")(e.zoo[o.application].categories)[0];o.category=a?a.id:"";var i=n("toArray")(e.zoo[o.application].types)[0];i&&(o.type=i.id),angular.forEach(e.zoo[o.application].types,function(e){angular.forEach(o.fields,function(a){if(o.mapping[e.id]=o.mapping[e.id]?o.mapping[e.id]:{},void 0==o.mapping[e.id][a.id]){var i=e.elements.filter(function(e){return e.type==a.def});o.mapping[e.id][a.id]=i.length?i[0].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)}}]).filter("zoo",function(){return function(e,a){return e&&angular.forEach(a,function(a,i){e=e.filter(function(e){return e[i]==a})}),e}});