"),t=e.extend({wrapper_autocomplete:n.parent(),wrapper_repr:n.parent().find("ul.grp-repr"),wrapper_search:n.parent().find("li.grp-search"),remove_link:n.next().next().hide(),loader:n.next().next().next().hide()},e.fn.grp_autocomplete_m2m.defaults,t),n.parent().find("ul.errorlist")&&n.parent().find("ul.errorlist").detach().appendTo(n.parent().parent()),n.parent().find("p.grp-help")&&n.parent().find("p.grp-help").detach().appendTo(n.parent().parent()),i(n,t),l(n,t),n.on("change focus keyup",function(){i(n,t)}),e("label[for='"+n.attr("id")+"']").each(function(){e(this).attr("for",n.attr("id")+"-autocomplete")}),t.wrapper_autocomplete.on("click",function(a){e(a.target).hasClass("related-lookup")||e(a.target).hasClass("grp-related-remove")||t.wrapper_search.find("input:first").trigger("focus")})})}};e.fn.grp_autocomplete_m2m=function(a){return t[a]?t[a].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof a&&a?(e.error("Method "+a+" does not exist on jQuery.grp_autocomplete_m2m"),!1):t.init.apply(this,arguments)};var a=function(){return e('
loader
')},r=function(t){var a=e('');return a.attr("id","remove_"+t),a.attr("href","javascript://"),a.attr("onClick","return removeRelatedObject(this);"),a.hover(function(){e(this).parent().toggleClass("grp-autocomplete-preremove")}),a},n=function(t,a,r){var n=e(''),l=e('').text(a);n.append(l),n.insertBefore(r.wrapper_search),l.on("click",function(a){var n=e(this).parent().parent().children("li").index(e(this).parent());!function(e,t,a){var r=[];e.val()&&(r=e.val().split(",")),r.splice(t,1),e.val(r.join(",")),e.trigger("change"),r.join(",")}(t,n),e(this).parent().remove(),t.val()?e(r.remove_link).show():e(r.remove_link).hide(),a.stopPropagation()}),l.hover(function(){e(this).parent().toggleClass("grp-autocomplete-preremove")})},l=function(t,a){a.wrapper_search.find("input:first").on("keydown",function(t){t.keyCode===e.ui.keyCode.TAB&&e(this).data("uiAutocomplete").menu.active&&t.preventDefault()}).on("focus",function(){a.wrapper_autocomplete.addClass("grp-state-focus")}).on("blur",function(){a.wrapper_autocomplete.removeClass("grp-state-focus")}).autocomplete({minLength:1,autoFocus:!0,delay:1e3,position:{my:"left top",at:"left bottom",of:a.wrapper_autocomplete},open:function(t,r){e(".ui-menu").width(a.wrapper_autocomplete.outerWidth()-6)},source:function(r,n){e.ajax({url:a.autocomplete_lookup_url,dataType:"json",data:"term="+encodeURIComponent(r.term)+"&app_label="+grappelli.get_app_label(t)+"&model_name="+grappelli.get_model_name(t)+"&query_string="+grappelli.get_query_string(t),beforeSend:function(e){a.loader.show()},success:function(t){n(e.map(t,function(e){return{label:e.label,value:e.value}}))},complete:function(e,t){a.loader.hide()}})},focus:function(){return!1},select:function(r,l){return n(t,l.item.label,a),function(e,t,a){var r=[];e.val()&&(r=e.val().split(",")),r.push(t),e.val(r.join(",")),e.trigger("change"),r.join(",")}(t,l.item.value),t.val()?e(a.remove_link).show():e(a.remove_link).hide(),e(this).val("").trigger("focus"),!1}}).data("ui-autocomplete")._renderItem=function(t,a){return a.value?e("").data("item.autocomplete",a).append(e("").text(a.label)).appendTo(t):e("").data("item.autocomplete",a).append(e("").text(a.label)).appendTo(t)}},i=function(t,a){e.getJSON(a.lookup_url,{object_id:t.val(),app_label:grappelli.get_app_label(t),model_name:grappelli.get_model_name(t)},function(r){a.wrapper_repr.find("li.grp-repr").remove(),a.wrapper_search.find("input").val(""),e.each(r,function(e){r[e].value&&n(t,r[e].label,a)}),t.val()?e(a.remove_link).show():e(a.remove_link).hide()})}}(grp.jQuery),function(e){e.fn.grp_collapsible_group=function(a){return a=e.extend({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(){}},a),this.each(function(){t(e(this),a)})};var t=function(e,t){t.on_init(e,t),a(e,t)},a=function(e,t){r(e,t),n(e,t)},r=function(t,a){t.find(a.open_handler_slctr).each(function(){e(this).on("click",function(){a.on_open(t,a),t.find(a.collapsible_container_slctr).removeClass(a.closed_css).addClass(a.open_css),t.removeClass(a.closed_css).addClass(a.open_css)})})},n=function(t,a){t.find(a.close_handler_slctr).each(function(){e(this).on("click",function(){a.on_close(t,a),t.find(a.collapsible_container_slctr).removeClass(a.open_css).addClass(a.closed_css)})})}}(grp.jQuery),function(e){e.fn.grp_collapsible=function(a){var r=e.extend({toggle_handler_slctr:".grp-collapse-handler:first",closed_css:"grp-closed",open_css:"grp-open",on_init:function(){},on_toggle:function(){}},a);return this.each(function(){t(e(this),r)})};var t=function(e,t){t.on_init(e,t),a(e,t)},a=function(e,t){r(e,t)},r=function(e,t){e.children(t.toggle_handler_slctr).on("click",function(){e.toggleClass(t.closed_css).toggleClass(t.open_css),t.on_toggle(e,t)})}}(grp.jQuery),function(e){e.fn.grp_inline=function(t){return t=e.extend({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(e){},onBeforeAdded:function(e){},onBeforeRemoved:function(e){},onBeforeDeleted:function(e){},onAfterInit:function(e){},onAfterAdded:function(e){},onAfterRemoved:function(e){},onAfterDeleted:function(e){}},t),this.each(function(){var a=e(this);a.find("#id_"+t.prefix+"-TOTAL_FORMS").attr("autocomplete","off"),initInlineForms(a,t),initAddButtons(a,t),addButtonHandler(a.find("a."+t.addCssClass),t),removeButtonHandler(a.find("a."+t.removeCssClass),t),deleteButtonHandler(a.find("a."+t.deleteCssClass),t)})},getFormIndex=function(e,t,a){var r=e.find("[id^='id_"+t.prefix+"']").attr("id");return r?parseInt(a.exec(r)[1],10):-1},updateFormIndex=function(t,a,r,n){t.find(":input,span,table,iframe,label,a,ul,p,img,div").each(function(){var t=e(this),a=t.attr("id"),l=t.attr("name"),i=t.attr("for"),o=t.attr("href"),p=t.attr("class"),s=t.attr("onclick");a&&t.attr("id",a.replace(r,n)),l&&t.attr("name",l.replace(r,n)),i&&t.attr("for",i.replace(r,n)),o&&t.attr("href",o.replace(r,n)),p&&t.attr("class",p.replace(r,n)),s&&t.attr("onclick",s.replace(r,n))}),t.find(".prepopulated_field").each(function(){var t=e(this).data("dependency_ids")||[],a=[];e.each(t,function(e,t){a.push(t.replace(r,n))}),e(this).data("dependency_ids",a)})};initInlineForms=function(t,a){t.find("div.grp-module").each(function(){var t=e(this);a.onBeforeInit(t),""!==t.attr("id")&&t.not("."+a.emptyCssClass).not(".grp-table").not(".grp-thead").not(".add-item").addClass(a.formCssClass),t.find("li.grp-delete-handler-container input").each(function(){e(this).is(":checked")&&t.hasClass("has_original")&&t.toggleClass(a.predeleteCssClass)}),a.onAfterInit(t)})},initAddButtons=function(e,t){var a=e.find("#id_"+t.prefix+"-TOTAL_FORMS"),r=e.find("#id_"+t.prefix+"-MAX_NUM_FORMS");e.find("a."+t.addCssClass);""!==r.val()&&r.val()-a.val()<=0&&hideAddButtons(e,t)},addButtonHandler=function(t,a){t.on("click",function(){var r=t.parents(".grp-group"),n=r.find("#id_"+a.prefix+"-TOTAL_FORMS"),l=r.find("#id_"+a.prefix+"-MAX_NUM_FORMS"),i=(r.find("a."+a.addCssClass),r.find("#"+a.prefix+"-empty"));a.onBeforeAdded(r);var o=parseInt(n.val(),10),p=i.clone(!0);p.removeClass(a.emptyCssClass).attr("id",i.attr("id").replace("-empty",o));updateFormIndex(p,a,/__prefix__/g,o),p.insertBefore(i).addClass(a.formCssClass),n.val(o+1),0!==l.val()&&""!==l.val()&&l.val()-n.val()<=0&&hideAddButtons(r,a),function(t,a){t.find(".prepopulated_field").each(function(){var t=e(this).data("dependency_ids")||[];e(this).prepopulate(t,e(this).attr("maxlength"))})}(p),a.onAfterAdded(p)})},removeButtonHandler=function(t,a){t.on("click",function(){var r=t.parents(".grp-group"),n=e(this).parents("."+a.formCssClass).first(),l=r.find("#id_"+a.prefix+"-TOTAL_FORMS"),i=r.find("#id_"+a.prefix+"-MAX_NUM_FORMS"),o=/-(\d+)-/,p=getFormIndex(n,a,o);a.onBeforeRemoved(n),n.remove(),l.val(parseInt(l.val(),10)-1),0!==i.val()&&i.val()-l.val()>0&&showAddButtons(r,a),r.find("."+a.formCssClass).each(function(){var t=e(this),r=getFormIndex(t,a,o);r>p&&updateFormIndex(t,a,o,"-"+(r-1)+"-")}),a.onAfterRemoved(r)})},deleteButtonHandler=function(t,a){t.on("click",function(){var t=e(this).prev(),r=e(this).parents("."+a.formCssClass).first();a.onBeforeDeleted(r),r.hasClass("has_original")&&(r.toggleClass(a.predeleteCssClass),t.prop("checked")?t.removeAttr("checked"):t.prop("checked",!0)),a.onAfterDeleted(r)})},hideAddButtons=function(e,t){var a=e.find("a."+t.addCssClass);a.hide().parents(".grp-add-item").hide(),a.closest(".grp-module.grp-transparent").hide()},showAddButtons=function(e,t){var a=e.find("a."+t.addCssClass);a.show().parents(".grp-add-item").show(),a.closest(".grp-module.grp-transparent").show()}}(grp.jQuery),function(e){var t={init:function(t){return t=e.extend({},e.fn.grp_related_fk.defaults,t),this.each(function(){var r=e(this),n=r.parent();n.find("a.related-lookup").next().is("strong")&&(n.find("a.related-lookup").get(0).nextSibling.nodeValue="",n.find("a.related-lookup").next("strong").remove()),n.find("a.related-lookup").after(t.placeholder),r.addClass("grp-has-related-lookup"),a(r,t),r.on("change focus keyup",function(){a(r,t)})})}};e.fn.grp_related_fk=function(a){return t[a]?t[a].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof a&&a?(e.error("Method "+a+" does not exist on jQuery.grp_related_fk"),!1):t.init.apply(this,arguments)};var a=function(t,a){var r=t.parent().find(".grp-placeholder-related-fk");e.getJSON(a.lookup_url,{object_id:t.val(),app_label:grappelli.get_app_label(t),model_name:grappelli.get_model_name(t),query_string:grappelli.get_query_string(t),to_field:grappelli.get_to_field(t)},function(t){""===t[0].label?r.hide():r.show(),t[0].safe?r.html(e('').html(t[0].label+"")):r.html(e('').text(t[0].label+""))})};e.fn.grp_related_fk.defaults={placeholder:'',repr_max_length:30,lookup_url:""}}(grp.jQuery),function(e){var t={init:function(t){return t=e.extend({},e.fn.grp_related_generic.defaults,t),this.each(function(){var l=e(this),i=e(t.content_type).val()||e(t.content_type).find(":checked").val();i&&l.after(t.placeholder).after(a(l.attr("id"),i)),l.addClass("grp-has-related-lookup"),i&&n(l,t),l.on("change focus keyup",function(){n(l,t)}),e(t.content_type).on("change",function(){r(e(this),t)})})}};e.fn.grp_related_generic=function(a){return t[a]?t[a].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof a&&a?(e.error("Method "+a+" does not exist on jQuery.grp_related_generic"),!1):t.init.apply(this,arguments)};var a=function(t,a){var r=e('');return r.attr("id","lookup_"+t),r.attr("href",window.ADMIN_URL+MODEL_URL_ARRAY[a].app+"/"+MODEL_URL_ARRAY[a].model+"/?"),r.attr("onClick","return showRelatedObjectLookupPopup(this);"),r},r=function(t,r){var n=e(r.object_id);n.val(""),n.parent().find("a.related-lookup").remove(),n.parent().find(".grp-placeholder-related-generic").remove();var l=e(t).val()||e(t).find(":checked").val();l&&n.after(r.placeholder).after(a(n.attr("id"),l))},n=function(t,a){var r=t.next().next();e.getJSON(a.lookup_url,{object_id:t.val(),app_label:grappelli.get_app_label(t),model_name:grappelli.get_model_name(t),query_string:grappelli.get_query_string(t)},function(t){""===t[0].label?r.hide():r.show(),t[0].safe?r.html(e('').html(t[0].label+"")):r.html(e('').text(t[0].label+""))})};e.fn.grp_related_generic.defaults={placeholder:'',repr_max_length:30,lookup_url:"",content_type:"",object_id:""}}(grp.jQuery),function(e){var t={init:function(t){return t=e.extend({},e.fn.grp_related_m2m.defaults,t),this.each(function(){var r=e(this);r.parent().find("a.related-lookup").after(t.placeholder),r.next().addClass("grp-m2m"),r.addClass("grp-has-related-lookup"),a(r,t),r.on("change focus keyup",function(){a(r,t)})})}};e.fn.grp_related_m2m=function(a){return t[a]?t[a].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof a&&a?(e.error("Method "+a+" does not exist on jQuery.grp_related_m2m"),!1):t.init.apply(this,arguments)};var a=function(t,a){e.getJSON(a.lookup_url,{object_id:t.val(),app_label:grappelli.get_app_label(t),model_name:grappelli.get_model_name(t),query_string:grappelli.get_query_string(t)},function(a){values=e.map(a,function(t,r){return a.length!==r+1||t.safe?a.length===r+1&&t.safe?e('').html(t.label+""):t.safe?e('').html(t.label+"").append(e('')):e('').text(t.label+"").append(e('')):e('').text(t.label+"")}),""===values?t.parent().find(".grp-placeholder-related-m2m").hide():t.parent().find(".grp-placeholder-related-m2m").show(),t.parent().find(".grp-placeholder-related-m2m").html(values)})};e.fn.grp_related_m2m.defaults={placeholder:'',repr_max_length:30,lookup_url:""}}(grp.jQuery),function(e){e.widget("ui.grp_timepicker",{options:{template:'',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 t=this;e(document).on("mousedown",function(a){if(t.timepicker.is(":visible")){var r=e(a.target);r[0].id==t.timepicker[0].id||0!==r.parents(t.options.timepicker_selector).length||r.hasClass("hasTimepicker")||r.hasClass("ui-timepicker-trigger")||t.timepicker.hide()}}),e(document).on("keyup",function(e){27==e.keyCode&&t.timepicker.hide()}),0===e(this.options.timepicker_selector).length&&e(this.options.template).appendTo("body"),this.timepicker=e(this.options.timepicker_selector),this.timepicker.hide(),this.element.addClass("hasTimepicker"),this.button=e(''),this.element.after(this.button),this.element.prop("disabled")?this.button.prop("disabled",!0):this.button.on("click",function(){t._toggleTimepicker()})},_toggleTimepicker:function(){this.timepicker.is(":visible")?this.timepicker.hide():(this.element.trigger("focus"),this._generateTimepickerContents(),this._showTimepicker())},_generateTimepickerContents:function(){var t=this,a="