1 line
No EOL
27 KiB
JavaScript
1 line
No EOL
27 KiB
JavaScript
var grp={jQuery:jQuery.noConflict(!0)},django={jQuery:grp.jQuery},jQuery=grp.jQuery,inputTypes=["[type='search']","[type='email']","[type='url']","[type='tel']","[type='number']","[type='range']","[type='date']","[type='month']","[type='week']","[type='time']","[type='datetime']","[type='datetime-local']","[type='color']"].join(",");!function(e){grappelli.getFormat=function(e){if("date"==e)return DATE_FORMAT.toLowerCase().replace(/%\w/g,function(e){return(e=e.replace(/%/,""))+e})},grappelli.cleanInputTypes=function(){e("form").each(function(){e(this).find(":input").filter(inputTypes).each(function(){e(this).attr("type","text")})})},grappelli.initDateAndTimePicker=function(){e("p.datetime").each(function(){var t=e(this).html();t=(t=t.replace(/\w*: /,"")).replace(/<br>[^<]*: /g,"<br>"),e(this).html(t)});var t={constrainInput:!1,showOn:"button",buttonImageOnly:!1,buttonText:"",dateFormat:grappelli.getFormat("date"),showButtonPanel:!0,showAnim:"",beforeShow:function(e,t,a){grappelli.datepicker_instance=this}},a=e("input[class*='vDateField']:not([id*='__prefix__'])");a.datepicker(t),"undefined"!=typeof IS_POPUP&&IS_POPUP&&a.datepicker("disable"),e(document).on("click",".ui-datepicker-current",function(){e.datepicker._selectDate(grappelli.datepicker_instance),grappelli.datepicker_instance=null}),e("input[class*='vTimeField']:not([id*='__prefix__'])").grp_timepicker()},grappelli.initFilter=function(t){if(e("a.grp-pulldown-handler").on("click",function(){var t=e(this).closest(".grp-pulldown-container");e(t).toggleClass("grp-pulldown-state-open").children(".grp-pulldown-content").toggle()}),e("a.grp-pulldown-handler").on("mouseout",function(){e(this).blur()}),t||e(".grp-filter-choice").change(function(){location.href=e(this).val()}),"confirm"===t){var a=window.location.search.replace("?","").split("&"),r=[];void 0!==a[0]&&""!==a[0]&&a.map(e=>{var t=e.split("=")[0];-1!=t.search("__")&&(t=e.split("__")[0]),-1===r.findIndex(e=>e.fieldName===t)?r.push({fieldName:t,values:[e]}):r.find(e=>e.fieldName===t).values.push(e)}),e(".grp-filter-choice").change(function(){var t=e(this).data("field-name"),a="?"!==e(this).val()&&e(this).val().replace("?",""),n=a&&a.split("&"),l=n&&n.filter(e=>e.includes(t)),i=r.findIndex(e=>e.fieldName===t);!(i<0)?l.length>0?r.find(e=>e.fieldName===t).values=l:r.splice(i,1):l.length>0&&r.push({fieldName:t,values:l});var o=r.flatMap(e=>e.values).join("&");e(this).closest(".grp-filter").find("#grp-filter-apply").attr("href","?"+o)})}},grappelli.initSearchbar=function(){e("input.grp-search-field").trigger("focus")},grappelli.updateSelectFilter=function(e){"undefined"!=typeof SelectFilter&&(e.find(".selectfilter").each(function(e,t){var a=t.name.split("-");SelectFilter.init(t.id,a[a.length-1],!1,"{% admin_media_prefix %}")}),e.find(".selectfilterstacked").each(function(e,t){var a=t.name.split("-");SelectFilter.init(t.id,a[a.length-1],!0,"{% admin_media_prefix %}")}))},grappelli.reinitDateTimeFields=function(e){e.find(".vDateField").datepicker({constrainInput:!1,showOn:"button",buttonImageOnly:!1,buttonText:"",dateFormat:grappelli.getFormat("date")}),e.find(".vTimeField").grp_timepicker()},grappelli.get_app_label=function(e){var t=e.next("a");if(t.length>0){var a=t.attr("href").split("?")[0].split("/");return a[a.length-3]}return!1},grappelli.get_model_name=function(e){var t=e.next("a");if(t.length>0){var a=t.attr("href").split("?")[0].split("/");return a[a.length-2]}return!1},grappelli.get_query_string=function(e){var t=e.next("a");if(t.length>0){var a=t.attr("href").split("/");return pairs=a[a.length-1].replace("?","").split("&"),pairs.join(":")}return!1},grappelli.get_to_field=function(e){var t=e.next("a");if(t.length>0&&-1!==t.attr("href").indexOf("_to_field"))for(var a=t.attr("href").split("/"),r=a[a.length-1].replace("?","").split("&"),n=0;n<r.length;n++)if(v=r[n].split("="),"_to_field"==v[0])return v[1];return!1}}(grp.jQuery),function(e){var t={init:function(t){return t=e.extend({},e.fn.grp_autocomplete_fk.defaults,t),this.each(function(){var i=e(this);i.attr({tabindex:"-1",readonly:"readonly"}).addClass("grp-autocomplete-hidden-field"),i.next().next()&&"errorlist"!=i.next().next().attr("class")&&"grp-help"!=i.next().next().attr("class")&&i.next().next().remove(),i.next().after(a).after(r(i.attr("id"))),i.parent().wrapInner("<div class='grp-autocomplete-wrapper-fk'></div>"),i.parent().prepend("<input id='"+i.attr("id")+"-autocomplete' type='text' class='vTextField' value='' />"),t=e.extend({wrapper_autocomplete:i.parent(),input_field:i.prev(),remove_link:i.next().next().hide(),loader:i.next().next().next().hide()},e.fn.grp_autocomplete_fk.defaults,t),l(i,t),n(i,t),i.on("change focus keyup",function(){l(i,t)}),e("label[for='"+i.attr("id")+"']").each(function(){e(this).attr("for",i.attr("id")+"-autocomplete")})})}};e.fn.grp_autocomplete_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_autocomplete_fk"),!1):t.init.apply(this,arguments)};var a=function(){return e('<div class="grp-loader">loader</div>')},r=function(t){var a=e('<a class="grp-related-remove"></a>');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){a.wrapper_autocomplete.find("input:first").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,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)+"&to_field="+grappelli.get_to_field(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,n){return a.input_field.val(n.item.label),t.val(n.item.value),t.trigger("change"),t.val()?e(a.remove_link).show():e(a.remove_link).hide(),!1}}).data("ui-autocomplete")._renderItem=function(t,a){return a.value?e("<li></li>").data("item.autocomplete",a).append(e("<a></a>").text(a.label)).appendTo(t):e("<li class='ui-state-disabled'></li>").data("item.autocomplete",a).append(e("<span class='error'></span>").text(a.label)).appendTo(t)}},l=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),to_field:grappelli.get_to_field(t)},function(r){e.each(r,function(n){a.input_field.val(r[n].label),t.val()?e(a.remove_link).show():e(a.remove_link).hide()})})};e.fn.grp_autocomplete_fk.defaults={autocomplete_lookup_url:"",lookup_url:""}}(grp.jQuery),function(e){var t={init:function(t){return t=e.extend({},e.fn.grp_autocomplete_generic.defaults,t),this.each(function(){var p=e(this);p.attr({tabindex:"-1",readonly:"readonly"}).addClass("grp-autocomplete-hidden-field");var s=e(t.content_type).val()||e(t.content_type).find(":checked").val();s&&p.after(a).after(r(p.attr("id"))).after(n(p.attr("id"),s)),p.parent().wrapInner("<div class='grp-autocomplete-wrapper-fk'></div>"),p.parent().prepend("<input id='"+p.attr("id")+"-autocomplete' type='text' class='vTextField' value='' />"),t=e.extend({wrapper_autocomplete:e(this).parent(),input_field:e(this).prev(),remove_link:p.nextAll("a.grp-related-remove").hide(),loader:p.nextAll("div.grp-loader").hide()},e.fn.grp_autocomplete_generic.defaults,t),s&&o(p,t),i(p,t),p.on("change focus keyup",function(){o(p,t)}),e(t.content_type).on("change",function(){l(e(this),t)}),e("label[for='"+p.attr("id")+"']").each(function(){e(this).attr("for",p.attr("id")+"-autocomplete")})})}};e.fn.grp_autocomplete_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_autocomplete_generic"),!1):t.init.apply(this,arguments)};var a=function(){return e('<div class="grp-loader">loader</div>')},r=function(t){var a=e('<a class="grp-related-remove"></a>');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){var r=e('<a class="related-lookup"></a>');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},l=function(t,l){var i=e(l.object_id);i.val(""),i.prev().val(""),i.nextAll("a.related-lookup").remove(),i.nextAll("a.grp-related-remove").remove(),i.nextAll("div.grp-loader").remove();var o=e(t).val()||e(t).find(":checked").val();o&&(i.after(a).after(r(i.attr("id"))).after(n(i.attr("id"),o)),l.remove_link=i.nextAll("a.grp-related-remove").hide(),l.loader=i.nextAll("div.grp-loader").hide())},i=function(t,a){a.wrapper_autocomplete.find("input:first").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,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(t){if(!(e(a.content_type).val()||e(a.content_type).find(":checked").val()))return!1;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,n){return a.input_field.val(n.item.label),t.val(n.item.value),t.trigger("change"),t.val()?e(a.remove_link).show():e(a.remove_link).hide(),!1}}).data("ui-autocomplete")._renderItem=function(t,a){return a.value?e("<li></li>").data("item.autocomplete",a).append(e("<a></a>").text(a.label)).appendTo(t):e("<li class='ui-state-disabled'></li>").data("item.autocomplete",a).append(e("<span class='error'></span>").text(a.label)).appendTo(t)}},o=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){e.each(r,function(n){a.input_field.val(r[n].label),t.val()?e(a.remove_link).show():e(a.remove_link).hide()})})};e.fn.grp_autocomplete_generic.defaults={autocomplete_lookup_url:"",lookup_url:"",content_type:"",object_id:""}}(grp.jQuery),function(e){var t={init:function(t){return t=e.extend({},e.fn.grp_autocomplete_m2m.defaults,t),this.each(function(){var n=e(this);n.attr({tabindex:"-1",readonly:"readonly"}).addClass("grp-autocomplete-hidden-field"),n.next().after(a).after(r(n.attr("id"))),n.parent().wrapInner("<div class='grp-autocomplete-wrapper-m2m'></div>"),n.parent().prepend("<ul class='grp-repr'><li class='grp-search'><input id='"+n.attr("id")+"-autocomplete' type='text' class='vTextField' value='' /></li></ul>"),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('<div class="grp-loader">loader</div>')},r=function(t){var a=e('<a class="grp-related-remove"></a>');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('<li class="grp-repr"></li>'),l=e('<a class="grp-m2m-remove" href="javascript://"></a>').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("<li></li>").data("item.autocomplete",a).append(e("<a></a>").text(a.label)).appendTo(t):e("<li class='ui-state-disabled'></li>").data("item.autocomplete",a).append(e("<span class='error'></span>").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('<span class="grp-placeholder-label"></span>').html(t[0].label+"")):r.html(e('<span class="grp-placeholder-label"></span>').text(t[0].label+""))})};e.fn.grp_related_fk.defaults={placeholder:'<div class="grp-placeholder-related-fk"></div>',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('<a class="related-lookup"></a>');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('<span class="grp-placeholder-label"></span>').html(t[0].label+"")):r.html(e('<span class="grp-placeholder-label"></span>').text(t[0].label+""))})};e.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(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('<span class="grp-placeholder-label"></span>').html(t.label+""):t.safe?e('<span class="grp-placeholder-label"></span>').html(t.label+"").append(e('<span class="grp-separator"></span>')):e('<span class="grp-placeholder-label"></span>').text(t.label+"").append(e('<span class="grp-separator"></span>')):e('<span class="grp-placeholder-label"></span>').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:'<div class="grp-placeholder-related-m2m"></div>',repr_max_length:30,lookup_url:""}}(grp.jQuery),function(e){e.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 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('<button type="button" class="ui-timepicker-trigger"></button>'),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="<ul>";0===this.options.time_list.length&&(this.options.time_list=this.options.default_time_list);for(var r=0;r<this.options.time_list.length;r++)if("now"==this.options.time_list[r]){var n=new Date,l=n.getHours(),i=n.getMinutes();a+='<li class="ui-state-active row">'+(l=l<10?"0"+l:l)+":"+(i=i<10?"0"+i:i)+"</li>"}else a+='<li class="ui-state-default row">'+this.options.time_list[r]+"</li>";a+="</ul>",this.timepicker.html(a),this.timepicker.find("li").on("click",function(){e(this).parent().children("li").removeClass("ui-state-active"),e(this).addClass("ui-state-active"),t.element.val(e(this).html()),t.timepicker.hide()})},_showTimepicker:function(){var e=document.documentElement.clientHeight,t=document.documentElement.scrollTop||document.body.scrollTop,a=this.element.outerHeight(),r=this.timepicker.outerHeight()+a,n=this.element.offset().top,l=this.element.offset().left;if(n-t+r+60<e){var i=n+a;this.timepicker.css("left",l+"px").css("top",i+"px")}else{var o=n-r+a;this.timepicker.css("left",l+"px").css("top",o+"px")}this.timepicker.show()},destroy:function(){e.Widget.prototype.destroy.apply(this,arguments)}})}(grp.jQuery); |