gestioCOF/static/grappelli/js/grappelli.min.js
2016-05-21 23:57:36 +02:00

1 line
No EOL
28 KiB
JavaScript

var grp={jQuery:jQuery.noConflict(true)};var django={jQuery:grp.jQuery.noConflict(true)};(function(a){grappelli.getFormat=function(b){if(b=="date"){var c=DATE_FORMAT.toLowerCase().replace(/%\w/g,function(d){d=d.replace(/%/,"");return d+d});return c}};grappelli.initDateAndTimePicker=function(){a("p.datetime").each(function(){var d=a(this).html();d=d.replace(/^\w*: /,"");d=d.replace(/<br>[^<]*: /g,"<br>");a(this).html(d)});var c={constrainInput:false,showOn:"button",buttonImageOnly:false,buttonText:"",dateFormat:grappelli.getFormat("date"),showButtonPanel:true,showAnim:"",beforeShow:function(d,f,e){grappelli.datepicker_instance=this}};var b=a("input[class*='vDateField']:not([id*='__prefix__'])");b.datepicker(c);if(typeof IS_POPUP!="undefined"&&IS_POPUP){b.datepicker("disable")}a(".ui-datepicker-current").on("click",function(){a.datepicker._selectDate(grappelli.datepicker_instance);grappelli.datepicker_instance=null});a("input[class*='vTimeField']:not([id*='__prefix__'])").grp_timepicker()};grappelli.initFilter=function(){a("a.grp-pulldown-handler").click(function(){var b=a(this).closest(".grp-pulldown-container");a(b).toggleClass("grp-pulldown-state-open").children(".grp-pulldown-content").toggle()});a("a.grp-pulldown-handler").bind("mouseout",function(){a(this).blur()});a(".grp-filter-choice").change(function(){location.href=a(this).val()})};grappelli.initSearchbar=function(){var b=a("input.grp-search-field");b.focus()};grappelli.updateSelectFilter=function(b){if(typeof SelectFilter!="undefined"){b.find(".selectfilter").each(function(c,e){var d=e.name.split("-");SelectFilter.init(e.id,d[d.length-1],false,"{% admin_media_prefix %}")});b.find(".selectfilterstacked").each(function(c,e){var d=e.name.split("-");SelectFilter.init(e.id,d[d.length-1],true,"{% admin_media_prefix %}")})}};grappelli.reinitDateTimeFields=function(b){b.find(".vDateField").datepicker({constrainInput:false,showOn:"button",buttonImageOnly:false,buttonText:"",dateFormat:grappelli.getFormat("date")});b.find(".vTimeField").grp_timepicker()};grappelli.get_app_label=function(d){var c=d.next("a");if(c.length>0){var b=c.attr("href").split("/");return b[b.length-3]}return false};grappelli.get_model_name=function(d){var c=d.next("a");if(c.length>0){var b=c.attr("href").split("/");return b[b.length-2]}return false};grappelli.get_query_string=function(d){var c=d.next("a");if(c.length>0){var b=c.attr("href").split("/");pairs=b[b.length-1].replace("?","").split("&");return pairs.join(":")}return false}})(grp.jQuery);(function(c){c.fn.grp_collapsible=function(e){var g={toggle_handler_slctr:".grp-collapse-handler:first",closed_css:"grp-closed",open_css:"grp-open",on_init:function(){},on_toggle:function(){}};var f=c.extend(g,e);return this.each(function(){b(c(this),f)})};var b=function(f,e){e.on_init(f,e);a(f,e)};var a=function(f,e){d(f,e)};var d=function(f,e){f.children(e.toggle_handler_slctr).click(function(){f.toggleClass(e.closed_css).toggleClass(e.open_css);e.on_toggle(f,e)})}})(grp.jQuery);(function(d){d.fn.grp_collapsible_group=function(f){var g={open_handler_slctr:".grp-open-handler",close_handler_slctr:".grp-close-handler",collapsible_container_slctr:".grp-collapse",closed_css:"grp-closed",open_css:"grp-open",on_init:function(){},on_open:function(){},on_close:function(){}};f=d.extend(g,f);return this.each(function(){c(d(this),f)})};var c=function(g,f){f.on_init(g,f);b(g,f)};var b=function(g,f){a(g,f);e(g,f)};var a=function(g,f){g.find(f.open_handler_slctr).each(function(){d(this).click(function(){f.on_open(g,f);g.find(f.collapsible_container_slctr).removeClass(f.closed_css).addClass(f.open_css);g.removeClass(f.closed_css).addClass(f.open_css)})})};var e=function(g,f){g.find(f.close_handler_slctr).each(function(){d(this).click(function(){f.on_close(g,f);g.find(f.collapsible_container_slctr).removeClass(f.open_css).addClass(f.closed_css)})})}})(grp.jQuery);(function(a){a.widget("ui.grp_timepicker",{options:{template:'<div id="ui-timepicker" class="module" style="position: absolute; display: none;"></div>',timepicker_selector:"#ui-timepicker",offset:{top:0},default_time_list:["now","00:00","01:00","02:00","03:00","04:00","05:00","06:00","07:00","08:00","09:00","10:00","11:00","12:00","13:00","14:00","15:00","16:00","17:00","18:00","19:00","20:00","21:00","22:00","23:00"],time_list:[]},_create:function(){var b=this;a(document).mousedown(function(d){if(b.timepicker.is(":visible")){var c=a(d.target);if(c[0].id!=b.timepicker[0].id&&c.parents(b.options.timepicker_selector).length===0&&!c.hasClass("hasTimepicker")&&!c.hasClass("ui-timepicker-trigger")){b.timepicker.hide()}}});a(document).keyup(function(c){if(c.keyCode==27){b.timepicker.hide()}});if(a(this.options.timepicker_selector).size()===0){a(this.options.template).appendTo("body")}this.timepicker=a(this.options.timepicker_selector);this.timepicker.hide();this.element.addClass("hasTimepicker");this.button=a('<button type="button" class="ui-timepicker-trigger"></button>');this.element.after(this.button);if(this.element.prop("disabled")){this.button.prop("disabled",true)}else{this.button.click(function(){b._toggleTimepicker()})}},_toggleTimepicker:function(){if(this.timepicker.is(":visible")){this.timepicker.hide()}else{this.element.focus();this._generateTimepickerContents();this._showTimepicker()}},_generateTimepickerContents:function(){var d=this,b="<ul>";if(this.options.time_list.length===0){this.options.time_list=this.options.default_time_list}for(var g=0;g<this.options.time_list.length;g++){if(this.options.time_list[g]=="now"){var e=new Date(),c=e.getHours(),f=e.getMinutes();c=((c<10)?"0"+c:c);f=((f<10)?"0"+f:f);b+='<li class="ui-state-active row">'+c+":"+f+"</li>"}else{b+='<li class="ui-state-default row">'+this.options.time_list[g]+"</li>"}}b+="</ul>";this.timepicker.html(b);this.timepicker.find("li").click(function(){a(this).parent().children("li").removeClass("ui-state-active");a(this).addClass("ui-state-active");d.element.val(a(this).html());d.timepicker.hide()})},_showTimepicker:function(){var f=document.documentElement.clientHeight;var i=document.documentElement.scrollTop||document.body.scrollTop;var b=this.element.outerHeight();var e=this.timepicker.outerHeight()+b;var c=this.element.offset().top;var d=this.element.offset().left;var j=c-i+e+60;if(j<f){var h=c+b;this.timepicker.css("left",d+"px").css("top",h+"px")}else{var g=c-e+b;this.timepicker.css("left",d+"px").css("top",g+"px")}this.timepicker.show()},destroy:function(){a.Widget.prototype.destroy.apply(this,arguments)}})})(grp.jQuery);(function(c){var b={init:function(d){d=c.extend({},c.fn.grp_related_fk.defaults,d);return this.each(function(){var f=c(this);var e=f.parent();if(e.find("a.related-lookup").next().is("strong")){e.find("a.related-lookup").get(0).nextSibling.nodeValue="";e.find("a.related-lookup").next("strong").remove()}e.find("a.related-lookup").after(d.placeholder);f.addClass("grp-has-related-lookup");a(f,d);f.bind("change focus keyup",function(){a(f,d)})})}};c.fn.grp_related_fk=function(d){if(b[d]){return b[d].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof d==="object"||!d){return b.init.apply(this,arguments)}else{c.error("Method "+d+" does not exist on jQuery.grp_related_fk")}}return false};var a=function(e,d){var f=e.parent().find(".grp-placeholder-related-fk");c.getJSON(d.lookup_url,{object_id:e.val(),app_label:grappelli.get_app_label(e),model_name:grappelli.get_model_name(e),query_string:grappelli.get_query_string(e)},function(g){if(g[0].label===""){f.hide()}else{f.show()}f.html('<span class="grp-placeholder-label">'+g[0].label+"</span>")})};c.fn.grp_related_fk.defaults={placeholder:'<div class="grp-placeholder-related-fk"></div>',repr_max_length:30,lookup_url:""}})(grp.jQuery);(function(c){var b={init:function(d){d=c.extend({},c.fn.grp_related_m2m.defaults,d);return this.each(function(){var e=c(this);e.parent().find("a.related-lookup").after(d.placeholder);e.next().addClass("grp-m2m");e.addClass("grp-has-related-lookup");a(e,d);e.bind("change focus keyup",function(){a(e,d)})})}};c.fn.grp_related_m2m=function(d){if(b[d]){return b[d].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof d==="object"||!d){return b.init.apply(this,arguments)}else{c.error("Method "+d+" does not exist on jQuery.grp_related_m2m")}}return false};var a=function(e,d){c.getJSON(d.lookup_url,{object_id:e.val(),app_label:grappelli.get_app_label(e),model_name:grappelli.get_model_name(e),query_string:grappelli.get_query_string(e)},function(f){values=c.map(f,function(g){return'<span class="grp-placeholder-label">'+g.label+"</span>"});if(values===""){e.parent().find(".grp-placeholder-related-m2m").hide()}else{e.parent().find(".grp-placeholder-related-m2m").show()}e.parent().find(".grp-placeholder-related-m2m").html(values.join('<span class="grp-separator"></span>'))})};c.fn.grp_related_m2m.defaults={placeholder:'<div class="grp-placeholder-related-m2m"></div>',repr_max_length:30,lookup_url:""}})(grp.jQuery);(function(d){var b={init:function(f){f=d.extend({},d.fn.grp_related_generic.defaults,f);return this.each(function(){var g=d(this);var h=d(f.content_type).val()||d(f.content_type).find(":checked").val();if(h){g.after(f.placeholder).after(e(g.attr("id"),h))}g.addClass("grp-has-related-lookup");if(h){a(g,f)}g.bind("change focus keyup",function(){a(g,f)});d(f.content_type).bind("change",function(){c(d(this),f)})})}};d.fn.grp_related_generic=function(f){if(b[f]){return b[f].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof f==="object"||!f){return b.init.apply(this,arguments)}else{d.error("Method "+f+" does not exist on jQuery.grp_related_generic")}}return false};var e=function(h,g){var f=d('<a class="related-lookup"></a>');f.attr("id","lookup_"+h);f.attr("href","../../../"+MODEL_URL_ARRAY[g].app+"/"+MODEL_URL_ARRAY[g].model+"/?t=id");f.attr("onClick","return showRelatedObjectLookupPopup(this);");return f};var c=function(g,f){var h=d(f.object_id);h.val("");h.parent().find("a.related-lookup").remove();h.parent().find(".grp-placeholder-related-generic").remove();var i=d(g).val()||d(g).find(":checked").val();if(i){h.after(f.placeholder).after(e(h.attr("id"),i))}};var a=function(g,f){var h=g.next().next();d.getJSON(f.lookup_url,{object_id:g.val(),app_label:grappelli.get_app_label(g),model_name:grappelli.get_model_name(g),query_string:grappelli.get_query_string(g)},function(i){if(i[0].label===""){h.hide()}else{h.show()}h.html('<span class="grp-placeholder-label">'+i[0].label+"</span>")})};d.fn.grp_related_generic.defaults={placeholder:'<div class="grp-placeholder-related-generic" style="display:none"></div>',repr_max_length:30,lookup_url:"",content_type:"",object_id:""}})(grp.jQuery);(function(f){var d={init:function(g){g=f.extend({},f.fn.grp_autocomplete_fk.defaults,g);return this.each(function(){var h=f(this);h.attr({tabindex:"-1",readonly:"readonly"}).addClass("grp-autocomplete-hidden-field");if(h.next().next()&&h.next().next().attr("class")!="errorlist"&&h.next().next().attr("class")!="grp-help"){h.next().next().remove()}h.next().after(b).after(a(h.attr("id")));h.parent().wrapInner("<div class='grp-autocomplete-wrapper-fk'></div>");h.parent().prepend("<input id='"+h.attr("id")+"-autocomplete' type='text' class='vTextField' value='' />");g=f.extend({wrapper_autocomplete:h.parent(),input_field:h.prev(),remove_link:h.next().next().hide(),loader:h.next().next().next().hide()},f.fn.grp_autocomplete_fk.defaults,g);c(h,g);e(h,g);h.bind("change focus keyup",function(){c(h,g)});f("label[for='"+h.attr("id")+"']").each(function(){f(this).attr("for",h.attr("id")+"-autocomplete")})})}};f.fn.grp_autocomplete_fk=function(g){if(d[g]){return d[g].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof g==="object"||!g){return d.init.apply(this,arguments)}else{f.error("Method "+g+" does not exist on jQuery.grp_autocomplete_fk")}}return false};var b=function(){var g=f('<div class="grp-loader">loader</div>');return g};var a=function(h){var g=f('<a class="grp-related-remove"></a>');g.attr("id","remove_"+h);g.attr("href","javascript://");g.attr("onClick","return removeRelatedObject(this);");g.hover(function(){f(this).parent().toggleClass("grp-autocomplete-preremove")});return g};var e=function(h,g){g.wrapper_autocomplete.find("input:first").bind("focus",function(){g.wrapper_autocomplete.addClass("grp-state-focus")}).bind("blur",function(){g.wrapper_autocomplete.removeClass("grp-state-focus")}).autocomplete({minLength:1,delay:1000,source:function(j,i){f.ajax({url:g.autocomplete_lookup_url,dataType:"json",data:"term="+encodeURIComponent(j.term)+"&app_label="+grappelli.get_app_label(h)+"&model_name="+grappelli.get_model_name(h)+"&query_string="+grappelli.get_query_string(h),beforeSend:function(k){g.loader.show()},success:function(k){i(f.map(k,function(l){return{label:l.label,value:l.value}}))},complete:function(k,l){g.loader.hide()}})},focus:function(){return false},select:function(i,j){g.input_field.val(j.item.label);h.val(j.item.value);h.val()?f(g.remove_link).show():f(g.remove_link).hide();return false}}).data("ui-autocomplete")._renderItem=function(i,j){if(!j.value){return f("<li></li>").data("item.autocomplete",j).append("<span class='error'>"+j.label).appendTo(i)}else{return f("<li></li>").data("item.autocomplete",j).append("<a>"+j.label).appendTo(i)}}};var c=function(h,g){f.getJSON(g.lookup_url,{object_id:h.val(),app_label:grappelli.get_app_label(h),model_name:grappelli.get_model_name(h)},function(i){f.each(i,function(j){g.input_field.val(i[j].label);h.val()?f(g.remove_link).show():f(g.remove_link).hide()})})};f.fn.grp_autocomplete_fk.defaults={autocomplete_lookup_url:"",lookup_url:""}})(grp.jQuery);(function(e){var c={init:function(j){j=e.extend({},e.fn.grp_autocomplete_m2m.defaults,j);return this.each(function(){var k=e(this);k.attr({tabindex:"-1",readonly:"readonly"}).addClass("grp-autocomplete-hidden-field");k.next().after(g).after(d(k.attr("id")));k.parent().wrapInner("<div class='grp-autocomplete-wrapper-m2m'></div>");k.parent().prepend("<ul class='grp-repr'><li class='grp-search'><input id='"+k.attr("id")+"-autocomplete' type='text' class='vTextField' value='' /></li></ul>");j=e.extend({wrapper_autocomplete:k.parent(),wrapper_repr:k.parent().find("ul.grp-repr"),wrapper_search:k.parent().find("li.grp-search"),remove_link:k.next().next().hide(),loader:k.next().next().next().hide()},e.fn.grp_autocomplete_m2m.defaults,j);if(k.parent().find("ul.errorlist")){k.parent().find("ul.errorlist").detach().appendTo(k.parent().parent())}a(k,j);b(k,j);k.bind("change focus keyup",function(){a(k,j)});e("label[for='"+k.attr("id")+"']").each(function(){e(this).attr("for",k.attr("id")+"-autocomplete")});j.wrapper_autocomplete.bind("click",function(l){if(!e(l.target).hasClass("related-lookup")&&!e(l.target).hasClass("grp-related-remove")){j.wrapper_search.find("input:first").focus()}})})}};e.fn.grp_autocomplete_m2m=function(j){if(c[j]){return c[j].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof j==="object"||!j){return c.init.apply(this,arguments)}else{e.error("Method "+j+" does not exist on jQuery.grp_autocomplete_m2m")}}return false};var f=function(l,m,k){var j=[];if(l.val()){j=l.val().split(",")}j.push(m);l.val(j.join(","));return j.join(",")};var i=function(m,j,l){var k=[];if(m.val()){k=m.val().split(",")}k.splice(j,1);m.val(k.join(","));return k.join(",")};var g=function(){var j=e('<div class="grp-loader">loader</div>');return j};var d=function(k){var j=e('<a class="grp-related-remove"></a>');j.attr("id","remove_"+k);j.attr("href","javascript://");j.attr("onClick","return removeRelatedObject(this);");j.hover(function(){e(this).parent().toggleClass("grp-autocomplete-preremove")});return j};var h=function(n,m,l){var k=e('<li class="grp-repr"></li>');var j=e('<a class="grp-m2m-remove" href="javascript://">'+m+"</a>");k.append(j);k.insertBefore(l.wrapper_search);j.bind("click",function(o){var p=e(this).parent().parent().children("li").index(e(this).parent());i(n,p,l);e(this).parent().remove();n.val()?e(l.remove_link).show():e(l.remove_link).hide();o.stopPropagation()});j.hover(function(){e(this).parent().toggleClass("grp-autocomplete-preremove")})};var b=function(k,j){j.wrapper_search.find("input:first").bind("keydown",function(l){if(l.keyCode===e.ui.keyCode.TAB&&e(this).data("autocomplete").menu.active){l.preventDefault()}}).bind("focus",function(){j.wrapper_autocomplete.addClass("grp-state-focus")}).bind("blur",function(){j.wrapper_autocomplete.removeClass("grp-state-focus")}).autocomplete({minLength:1,delay:1000,position:{my:"left top",at:"left bottom",of:j.wrapper_autocomplete},open:function(l,m){e(".ui-menu").width(j.wrapper_autocomplete.outerWidth()-6)},source:function(m,l){e.ajax({url:j.autocomplete_lookup_url,dataType:"json",data:"term="+encodeURIComponent(m.term)+"&app_label="+grappelli.get_app_label(k)+"&model_name="+grappelli.get_model_name(k)+"&query_string="+grappelli.get_query_string(k),beforeSend:function(n){j.loader.show()},success:function(n){l(e.map(n,function(o){return{label:o.label,value:o.value}}))},complete:function(n,o){j.loader.hide()}})},focus:function(){return false},select:function(l,m){h(k,m.item.label,j);f(k,m.item.value,j);k.val()?e(j.remove_link).show():e(j.remove_link).hide();e(this).val("").focus();return false}}).data("ui-autocomplete")._renderItem=function(l,m){if(!m.value){return e("<li></li>").data("item.autocomplete",m).append("<span class='error'>"+m.label).appendTo(l)}else{return e("<li></li>").data("item.autocomplete",m).append("<a>"+m.label).appendTo(l)}}};var a=function(k,j){e.getJSON(j.lookup_url,{object_id:k.val(),app_label:grappelli.get_app_label(k),model_name:grappelli.get_model_name(k)},function(l){j.wrapper_repr.find("li.grp-repr").remove();j.wrapper_search.find("input").val("");e.each(l,function(m){if(l[m].value){h(k,l[m].label,j)}});k.val()?e(j.remove_link).show():e(j.remove_link).hide()})}})(grp.jQuery);(function(f){var d={init:function(g){g=f.extend({},f.fn.grp_autocomplete_fk.defaults,g);return this.each(function(){var h=f(this);h.attr({tabindex:"-1",readonly:"readonly"}).addClass("grp-autocomplete-hidden-field");if(h.next().next()&&h.next().next().attr("class")!="errorlist"&&h.next().next().attr("class")!="grp-help"){h.next().next().remove()}h.next().after(b).after(a(h.attr("id")));h.parent().wrapInner("<div class='grp-autocomplete-wrapper-fk'></div>");h.parent().prepend("<input id='"+h.attr("id")+"-autocomplete' type='text' class='vTextField' value='' />");g=f.extend({wrapper_autocomplete:h.parent(),input_field:h.prev(),remove_link:h.next().next().hide(),loader:h.next().next().next().hide()},f.fn.grp_autocomplete_fk.defaults,g);c(h,g);e(h,g);h.bind("change focus keyup",function(){c(h,g)});f("label[for='"+h.attr("id")+"']").each(function(){f(this).attr("for",h.attr("id")+"-autocomplete")})})}};f.fn.grp_autocomplete_fk=function(g){if(d[g]){return d[g].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof g==="object"||!g){return d.init.apply(this,arguments)}else{f.error("Method "+g+" does not exist on jQuery.grp_autocomplete_fk")}}return false};var b=function(){var g=f('<div class="grp-loader">loader</div>');return g};var a=function(h){var g=f('<a class="grp-related-remove"></a>');g.attr("id","remove_"+h);g.attr("href","javascript://");g.attr("onClick","return removeRelatedObject(this);");g.hover(function(){f(this).parent().toggleClass("grp-autocomplete-preremove")});return g};var e=function(h,g){g.wrapper_autocomplete.find("input:first").bind("focus",function(){g.wrapper_autocomplete.addClass("grp-state-focus")}).bind("blur",function(){g.wrapper_autocomplete.removeClass("grp-state-focus")}).autocomplete({minLength:1,delay:1000,source:function(j,i){f.ajax({url:g.autocomplete_lookup_url,dataType:"json",data:"term="+encodeURIComponent(j.term)+"&app_label="+grappelli.get_app_label(h)+"&model_name="+grappelli.get_model_name(h)+"&query_string="+grappelli.get_query_string(h),beforeSend:function(k){g.loader.show()},success:function(k){i(f.map(k,function(l){return{label:l.label,value:l.value}}))},complete:function(k,l){g.loader.hide()}})},focus:function(){return false},select:function(i,j){g.input_field.val(j.item.label);h.val(j.item.value);h.val()?f(g.remove_link).show():f(g.remove_link).hide();return false}}).data("ui-autocomplete")._renderItem=function(i,j){if(!j.value){return f("<li></li>").data("item.autocomplete",j).append("<span class='error'>"+j.label).appendTo(i)}else{return f("<li></li>").data("item.autocomplete",j).append("<a>"+j.label).appendTo(i)}}};var c=function(h,g){f.getJSON(g.lookup_url,{object_id:h.val(),app_label:grappelli.get_app_label(h),model_name:grappelli.get_model_name(h)},function(i){f.each(i,function(j){g.input_field.val(i[j].label);h.val()?f(g.remove_link).show():f(g.remove_link).hide()})})};f.fn.grp_autocomplete_fk.defaults={autocomplete_lookup_url:"",lookup_url:""}})(grp.jQuery);(function(g){var d={init:function(i){i=g.extend({},g.fn.grp_autocomplete_generic.defaults,i);return this.each(function(){var j=g(this);j.attr({tabindex:"-1",readonly:"readonly"}).addClass("grp-autocomplete-hidden-field");var k=g(i.content_type).val()||g(i.content_type).find(":checked").val();if(k){j.after(b).after(a(j.attr("id"))).after(h(j.attr("id"),k))}j.parent().wrapInner("<div class='grp-autocomplete-wrapper-fk'></div>");j.parent().prepend("<input id='"+j.attr("id")+"-autocomplete' type='text' class='vTextField' value='' />");i=g.extend({wrapper_autocomplete:g(this).parent(),input_field:g(this).prev(),remove_link:j.nextAll("a.grp-related-remove").hide(),loader:j.nextAll("div.grp-loader").hide()},g.fn.grp_autocomplete_generic.defaults,i);if(k){c(j,i)}f(j,i);j.bind("change focus keyup",function(){c(j,i)});g(i.content_type).bind("change",function(){e(g(this),i)});g("label[for='"+j.attr("id")+"']").each(function(){g(this).attr("for",j.attr("id")+"-autocomplete")})})}};g.fn.grp_autocomplete_generic=function(i){if(d[i]){return d[i].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof i==="object"||!i){return d.init.apply(this,arguments)}else{g.error("Method "+i+" does not exist on jQuery.grp_autocomplete_generic")}}return false};var b=function(){var i=g('<div class="grp-loader">loader</div>');return i};var a=function(j){var i=g('<a class="grp-related-remove"></a>');i.attr("id","remove_"+j);i.attr("href","javascript://");i.attr("onClick","return removeRelatedObject(this);");i.hover(function(){g(this).parent().toggleClass("grp-autocomplete-preremove")});return i};var h=function(k,j){var i=g('<a class="related-lookup"></a>');i.attr("id","lookup_"+k);i.attr("href","../../../"+MODEL_URL_ARRAY[j].app+"/"+MODEL_URL_ARRAY[j].model+"/?t=id");i.attr("onClick","return showRelatedObjectLookupPopup(this);");return i};var e=function(j,i){var k=g(i.object_id);k.val("");k.prev().val("");k.nextAll("a.related-lookup").remove();k.nextAll("a.grp-related-remove").remove();k.nextAll("div.grp-loader").remove();var l=g(j).val()||g(j).find(":checked").val();if(l){k.after(b).after(a(k.attr("id"))).after(h(k.attr("id"),l));i.remove_link=k.nextAll("a.grp-related-remove").hide();i.loader=k.nextAll("div.grp-loader").hide()}};var f=function(j,i){i.wrapper_autocomplete.find("input:first").bind("focus",function(){i.wrapper_autocomplete.addClass("grp-state-focus")}).bind("blur",function(){i.wrapper_autocomplete.removeClass("grp-state-focus")}).autocomplete({minLength:1,delay:1000,source:function(l,k){g.ajax({url:i.autocomplete_lookup_url,dataType:"json",data:"term="+encodeURIComponent(l.term)+"&app_label="+grappelli.get_app_label(j)+"&model_name="+grappelli.get_model_name(j)+"&query_string="+grappelli.get_query_string(j),beforeSend:function(m){var n=g(i.content_type).val()||g(i.content_type).find(":checked").val();if(n){i.loader.show()}else{return false}},success:function(m){k(g.map(m,function(n){return{label:n.label,value:n.value}}))},complete:function(m,n){i.loader.hide()}})},focus:function(){return false},select:function(k,l){i.input_field.val(l.item.label);j.val(l.item.value);j.val()?g(i.remove_link).show():g(i.remove_link).hide();return false}}).data("ui-autocomplete")._renderItem=function(k,l){if(!l.value){return g("<li></li>").data("item.autocomplete",l).append("<span class='error'>"+l.label).appendTo(k)}else{return g("<li></li>").data("item.autocomplete",l).append("<a>"+l.label).appendTo(k)}}};var c=function(j,i){g.getJSON(i.lookup_url,{object_id:j.val(),app_label:grappelli.get_app_label(j),model_name:grappelli.get_model_name(j)},function(k){g.each(k,function(l){i.input_field.val(k[l].label);j.val()?g(i.remove_link).show():g(i.remove_link).hide()})})};g.fn.grp_autocomplete_generic.defaults={autocomplete_lookup_url:"",lookup_url:"",content_type:"",object_id:""}})(grp.jQuery);(function(a){a.fn.grp_inline=function(b){var c={prefix:"form",addText:"add another",deleteText:"remove",addCssClass:"grp-add-handler",removeCssClass:"grp-remove-handler",deleteCssClass:"grp-delete-handler",emptyCssClass:"grp-empty-form",formCssClass:"grp-dynamic-form",predeleteCssClass:"grp-predelete",onBeforeInit:function(d){},onBeforeAdded:function(d){},onBeforeRemoved:function(d){},onBeforeDeleted:function(d){},onAfterInit:function(d){},onAfterAdded:function(d){},onAfterRemoved:function(d){},onAfterDeleted:function(d){}};b=a.extend(c,b);return this.each(function(){var e=a(this);var d=e.find("#id_"+b.prefix+"-TOTAL_FORMS");d.attr("autocomplete","off");initInlineForms(e,b);initAddButtons(e,b);addButtonHandler(e.find("a."+b.addCssClass),b);removeButtonHandler(e.find("a."+b.removeCssClass),b);deleteButtonHandler(e.find("a."+b.deleteCssClass),b)})};updateFormIndex=function(d,c,b,e){d.find(":input,span,table,iframe,label,a,ul,p,img,div").each(function(){var i=a(this),k=i.attr("id"),h=i.attr("name"),j=i.attr("for"),g=i.attr("href"),l=i.attr("class"),f=i.attr("onclick");if(k){i.attr("id",k.replace(b,e))}if(h){i.attr("name",h.replace(b,e))}if(j){i.attr("for",j.replace(b,e))}if(g){i.attr("href",g.replace(b,e))}if(l){i.attr("class",l.replace(b,e))}if(f){i.attr("onclick",f.replace(b,e))}})};initInlineForms=function(c,b){c.find("div.grp-module").each(function(){var d=a(this);b.onBeforeInit(d);if(d.attr("id")!==""){d.not("."+b.emptyCssClass).not(".grp-table").not(".grp-thead").not(".add-item").addClass(b.formCssClass)}d.find("li.grp-delete-handler-container input").each(function(){if(a(this).is(":checked")&&d.hasClass("has_original")){d.toggleClass(b.predeleteCssClass)}});b.onAfterInit(d)})};initAddButtons=function(d,c){var e=d.find("#id_"+c.prefix+"-TOTAL_FORMS");var b=d.find("#id_"+c.prefix+"-MAX_NUM_FORMS");var f=d.find("a."+c.addCssClass);if((b.val()!=="")&&(b.val()-e.val())<=0){hideAddButtons(d,c)}};addButtonHandler=function(c,b){c.bind("click",function(){var i=c.parents(".grp-group"),h=i.find("#id_"+b.prefix+"-TOTAL_FORMS"),e=i.find("#id_"+b.prefix+"-MAX_NUM_FORMS"),k=i.find("a."+b.addCssClass),j=i.find("#"+b.prefix+"-empty");b.onBeforeAdded(i);var d=parseInt(h.val(),10),g=j.clone(true);g.removeClass(b.emptyCssClass).attr("id",j.attr("id").replace("-empty",d));var f=/__prefix__/g;updateFormIndex(g,b,f,d);g.insertBefore(j).addClass(b.formCssClass);h.val(d+1);if((e.val()!==0)&&(e.val()!=="")&&(e.val()-h.val())<=0){hideAddButtons(i,b)}b.onAfterAdded(g)})};removeButtonHandler=function(c,b){c.bind("click",function(){var k=c.parents(".grp-group"),h=a(this).parents("."+b.formCssClass).first(),j=k.find("#id_"+b.prefix+"-TOTAL_FORMS"),e=k.find("#id_"+b.prefix+"-MAX_NUM_FORMS");b.onBeforeRemoved(h);h.remove();var d=parseInt(j.val(),10);j.val(d-1);if((e.val()!==0)&&(e.val()-j.val())>0){showAddButtons(k,b)}var g=/-\d+-/g,f=0;k.find("."+b.formCssClass).each(function(){updateFormIndex(a(this),b,g,"-"+f+"-");f++});b.onAfterRemoved(k)})};deleteButtonHandler=function(c,b){c.bind("click",function(){var d=a(this).prev(),e=a(this).parents("."+b.formCssClass).first();b.onBeforeDeleted(e);if(e.hasClass("has_original")){e.toggleClass(b.predeleteCssClass);if(d.prop("checked")){d.removeAttr("checked")}else{d.prop("checked",true)}}b.onAfterDeleted(e)})};hideAddButtons=function(c,b){var d=c.find("a."+b.addCssClass);d.hide().parents(".grp-add-item").hide()};showAddButtons=function(c,b){var d=c.find("a."+b.addCssClass);d.show().parents(".grp-add-item").show()}})(grp.jQuery);