!function(a,b){"use strict";function c(a,c){var d=this;c=b.extend({chooseText:"Choose Event",loadingText:ccmi18n.loadingText,inputName:"eventID",calendarID:0,closeOnComplete:!0,eventID:0},c),d.$element=a,d.options=c,d._chooseTemplate=_.template(d.chooseTemplate,{options:d.options}),d._loadingTemplate=_.template(d.loadingTemplate),d._eventLoadedTemplate=_.template(d.eventLoadedTemplate),d.$element.append(d._chooseTemplate),d.$element.unbind(".calendarEventSelector").on("click.calendarEventSelector","a[data-calendar-event-selector-link=choose]",function(a){a.preventDefault(),b.fn.dialog.open({title:c.chooseText,href:CCM_DISPATCHER_FILENAME+"/ccm/calendar/dialogs/choose_event?caID="+c.calendarID,width:"90%",modal:!0,height:"70%"})}),d.options.eventID&&d.loadEvent(d.options.eventID),ConcreteEvent.unsubscribe("CalendarEventSearchDialogSelectEvent"),ConcreteEvent.subscribe("CalendarEventSearchDialogSelectEvent",function(a,c){d.options.closeOnComplete&&b.fn.dialog.closeTop(),d.loadEvent(c.id)})}c.prototype={chooseTemplate:'<div class="ccm-item-selector"><input type="hidden" name="<%=options.inputName%>" value="0" /><a href="#" data-calendar-event-selector-link="choose"><%=options.chooseText%></a></div>',loadingTemplate:'<div class="ccm-item-selector"><div class="ccm-item-selector-choose"><input type="hidden" name="<%=options.inputName%>" value="<%=eventID%>"><i class="fa fa-spin fa-spinner"></i> <%=options.loadingText%></div></div>',eventLoadedTemplate:'<div class="ccm-item-selector"><div class="ccm-item-selector-item-selected"><input type="hidden" name="<%=inputName%>" value="<%=event.id%>" /><a data-calendar-event-selector-action="clear" href="#" class="ccm-item-selector-clear"><i class="fa fa-close"></i></a><div class="ccm-item-selector-item-selected-title"><%=event.title%></div></div></div>',loadEvent:function(a){var c=this;c.$element.html(c._loadingTemplate({options:c.options,eventID:a})),b.ajax({type:"post",dataType:"json",url:CCM_DISPATCHER_FILENAME+"/ccm/calendar/event/get_json",data:{eventID:a},error:function(a){ConcreteAlert.dialog("Error",a.responseText)},success:function(a){c.$element.html(c._eventLoadedTemplate({inputName:c.options.inputName,event:a})),c.$element.on("click.calendarEventSelector","a[data-calendar-event-selector-action=clear]",function(a){a.preventDefault(),c.$element.html(c._chooseTemplate)})}})}},b.fn.concreteCalendarEventSelector=function(a){return b.each(b(this),function(d,e){new c(b(this),a)})},a.ConcreteCalendarEventSelector=c}(this,jQuery);