-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.min.js
2 lines (2 loc) · 46.7 KB
/
app.min.js
1
2
function Ajax(){var t=this;this.response,this.xhttp,this.event,this.request,this.dataString,this.updateActivityInvitedUsers=function(n,i){t.dataString="activity_id="+n,t.dataString+="&friends_id="+i,t.request="updateActivityInvitedUsers",e()},this.fetchFriendsByName=function(n){t.dataString="searchstring="+n,t.request="fetchFriendsByName",e()},this.fetchInvitedUsersByActivityId=function(n){t.dataString="activity_id="+n,t.request="fetchInvitedUsersByActivityId",e()},this.declineActivityInvite=function(n,i){var i="undefined"!=typeof i?i:"AjaxComplete";t.dataString="activity_id="+n,t.request="declineActivityInvite",e(i)},this.acceptActivityInvite=function(n){t.dataString="activity_id="+n,t.request="acceptActivityInvite",e()},this.declineFriendRequest=function(n,i){t.dataString+="friend_id="+i,t.request="declineFriendRequest",e()},this.acceptFriendRequest=function(n,i){t.dataString+="friend_id="+i,t.request="acceptFriendRequest",e()},this.sendFriendRequest=function(n,i){t.dataString+="friend_id="+i,t.request="sendFriendRequest",e()},this.deleteActivity=function(n,i){var i="undefined"!=typeof i?i:"AjaxComplete";t.dataString="activity_id="+n,t.request="deleteActivity",e(i)},this.updateActivity=function(n,i){var i="undefined"!=typeof i?i:"AjaxComplete";t.dataString="activity_id="+n.id,t.dataString+="&activity_title="+n.title,t.dataString+="&activity_description="+n.description,t.dataString+="&activity_start="+n.activity_start,t.dataString+="&activity_end="+n.activity_end,t.dataString+="&invited_str="+n.invited_str,t.dataString+="&isOwner="+n.isOwner,t.request="updateActivity",e(i)},this.createActivity=function(n,i){var i="undefined"!=typeof i?i:"AjaxComplete";t.dataString="&title="+n.title,t.dataString+="&description="+n.description,t.dataString+="&activity_start="+n.activity_start,t.dataString+="&activity_end="+n.activity_end,t.dataString+="&date="+n.date,t.dataString+="&invited_str="+n.invited_str,t.request="createActivity",e(i)},this.fetchActivitiesByDate=function(n,i,a){var a="undefined"!=typeof a?a:"AjaxComplete";t.dataString="activity_start="+n,t.dataString+="&activity_end="+i,t.request="fetchActivitiesByDate",e(a)},this.fetchCountNotifications=function(n){var n="undefined"!=typeof n?n:"AjaxComplete";t.request="fetchCountNotifications",e(n)},this.fetchNotifications=function(n){var n="undefined"!=typeof n?n:"AjaxComplete";t.request="fetchNotifications",e(n)},this.answerNotification=function(n,i,a){var a="undefined"!=typeof a?a:"AjaxComplete";t.dataString+="¬ification_id="+n.getNotificationId(),t.dataString+="&action="+i,t.request="answerNotifications",e(a)},this.setNotificationsToRead=function(n){var n="undefined"!=typeof n?n:"AjaxComplete";t.request="setNotificationsToRead",e(n)},this.fetch=function(){var e=t.response;return t.response=[],e.length>0?JSON.parse(e):""};var e=function(e){var e="undefined"!=typeof e?e:"AjaxComplete";t.event=new Event(e),t.xhttp=new XMLHttpRequest,t.xhttp.onreadystatechange=function(){4==this.readyState&&200==this.status&&(t.response=this.responseText,window.dispatchEvent(t.event))},t.xhttp.open("POST",APP.DOMAIN+"/ajax-endpoint?request="+t.request,!0),t.xhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"),t.xhttp.send(t.dataString)}}function TimeGenerator(t){"use strict";var e=t,n=[],i=[],a=function(){for(var t,n=e/24,a=60/n,r=0;r<n;r++)t=r*a,t<10?i.push("0"+t.toString()):i.push(t.toString())},r=function(){for(var t,e=0;e<=24;e++)for(var a=0;a<i.length&&(t="",t+=e<10?"0"+e:e,t+=":",t+=i[a],n.push(t),24!==e);a++);};this.getTimeArr=function(){return n},this.getTimeString=function(){for(var t="",e=0;e<n.length;e++)t+=n[e]+"<br>";return t},a(),r()}function Button(t,e,n){var i,a=t,r=e,o=n;this.getElement=function(){return i},this.getRole=function(){return r};var d=function(){i=document.createElement("div"),i.className=o,i.innerHTML=a,i.setAttribute("data-role",r)};d()}function Input(t,e,n,i){var a,r,i="undefined"!=typeof i?i:"",o=t,d=e,s=n,c=i,l=!0,u=document.createElement("div");this.getElement=function(){return u},this.getInputElement=function(){return a},this.getValue=function(){return l=""!==a.value,a.value},this.getIsFilledIn=function(){return l},this.getRole=function(){return d};var v=function(){r=document.createElement("h6"),r.innerHTML=o,"textarea"===s?(a=document.createElement("textarea"),a.innerHTML=c):(a=document.createElement("input"),a.setAttribute("type",s),a.setAttribute("value",c)),a.setAttribute("data-role",d),a.classList.add("form-input"),u.classList.add("form-field"),u.appendChild(r),u.appendChild(a)};v()}function Time(t,e,n){var n="undefined"!=typeof n?n:"",i=t,a=e,r=n,o=!0,d=document.createElement("div"),s=document.createElement("h6"),c=document.createElement("select"),l=document.createElement("input"),u=new TimeGenerator(96),v=u.getTimeArr();this.getTimeWrapper=function(){return d},this.getTimeElement=function(){return c},this.getRole=function(){return a},this.getSelectedTime=function(){return v[c.selectedIndex]},this.getDateElement=function(){return o=""!==l.value,l},this.getIsFilledIn=function(){return o},this.setDateElement=function(t){l.value=t};var f=function(){if(s.innerHTML=i,d.appendChild(s),d.className="form-field","date"===a)l.setAttribute("data-role",a),l.className="form-input",l.value=r,"Desktop"===APP.USER_AGENT&&$(function(){$('input[data-role="date"]').datepicker({dateFormat:"yy-mm-dd"})}),d.appendChild(l);else{c.setAttribute("data-role",a);for(var t=0;t<v.length;t++){var e=document.createElement("option");e.setAttribute("value",v[t]),v[t]===r&&e.setAttribute("selected","selected"),e.text=v[t],c.appendChild(e)}d.appendChild(c)}};f()}function FormMap(){var t=[],e=[],n=[];this.getButtons=function(){return t},this.getInputs=function(){return e},this.getTimes=function(){return n},this.addButton=function(e,n,i){t.push(new Button(e,n,i))},this.addInput=function(t,n,i,a){e.push(new Input(t,n,i,a))},this.addTime=function(t,e,i){n.push(new Time(t,e,i))}}function Modal(t,e){var e="undefined"!=typeof e?e:"undefined",n=document.createElement("div"),i=document.createElement("div"),a=document.createElement("div"),r=document.createElement("div"),o=document.createElement("div"),d=document.createElement("form"),s=!1,c=-1,l=e,u=[],v=t.getInputs(),f=t.getButtons(),h=t.getTimes();this.getModal=function(){return n},this.getWrapper=function(){return i},this.disableInput=function(){for(var t=0;t<v.length;t++)v[t].getInputElement().setAttribute("readonly","readonly");for(var t=0;t<h.length;t++)h[t].getTimeElement().setAttribute("disabled","disabled"),h[t].getDateElement().setAttribute("readonly","readonly"),h[t].getDateElement().setAttribute("data-role","viewonly");s=!0};var g=function(){for(var t,e=0;e<f.length;e++){var n=f[e].getRole();"submit"===n&&(t=f[e].getElement(),t.addEventListener("click",L,!1)),"update"===n&&(t=f[e].getElement(),t.addEventListener("click",D,!1)),"cancel"===n&&(t=f[e].getElement(),t.addEventListener("click",w,!1)),"decline"===n&&(t=f[e].getElement(),t.addEventListener("click",y,!1)),"delete"===n&&(t=f[e].getElement(),t.addEventListener("click",A,!1))}},m=function(){for(var t,e,n=0;n<v.length;n++){var i=v[n].getRole();"friend-field"===i&&(t=v[n].getInputElement(),c=n,t.addEventListener("keyup",function(){clearTimeout(e),e=setTimeout(function(){M(t)},200)},!1))}},p=function(t){var e,n,i,a,r,o,d,s;"undefined"===l?(e="null",n="1"):(e=l.getId(),n=l.getIsOwner());for(var c=0;c<v.length;c++)s=v[c].getRole(),"title"===s&&(i=v[c].getValue()),"description"===s&&(a=v[c].getValue());for(var c=0;c<h.length;c++)s=h[c].getRole(),"start"===s&&(o=h[c].getSelectedTime()),"end"===s&&(d=h[c].getSelectedTime()),"date"===s&&(r=h[c].getDateElement().value);l=new ActivityData(e,i,a,r,o,d,n,u)},y=function(t){window.dispatchEvent(new CustomEvent("DeclineActivity",{detail:l})),w()},w=function(t){i.remove(),a.remove(),window.dispatchEvent(new CustomEvent("CloseForm"))},A=function(t){window.dispatchEvent(new CustomEvent("DeleteActivity",{detail:l})),w()},E=function(t){var e=this.getAttribute("data-userid");u.indexOf(e)===-1&&(u.push(e),r.innerHTML="",v[c].getInputElement().value="",o.appendChild(this))},I=function(t){if(c!==-1&&s===!1){var e=this.getAttribute("data-userid"),n=u.indexOf(e);u.splice(n,1),this.parentNode.removeChild(this)}},L=function(){p(),C()&&(window.dispatchEvent(new CustomEvent("CreateActivity",{detail:l})),w())},D=function(){p(),C()&&(window.dispatchEvent(new CustomEvent("UpdateActivity",{detail:l})),w())},C=function(){for(var t=!0,e=0;e<v.length;e++)v[e].getIsFilledIn()===!1&&(v[e].getInputElement().classList.add("form-error"),t=!1);for(var e=0;e<h.length;e++)h[e].getIsFilledIn()===!1&&(""===h[e].getDateElement().value&&h[e].getDateElement().classList.add("form-error"),t=!1);return!(l.getStart()===l.getEnd()||t!==!0)},T=function(){if(c!==-1&&"undefined"!==l&&l.getInvited().length>0){var t,e,n=new Ajax,i=document.createElement("h6");i.innerHTML="Invited",o.appendChild(i),window.addEventListener("AjaxComplete",function(){t=n.fetch();for(var i=0;i<t.length;i++)e=x(t,i),e.addEventListener("click",I,!1),o.appendChild(e),u.push(t[i].id)}),n.fetchInvitedUsersByActivityId(l.getId())}},M=function(t){var e,n,i=new Ajax,a=t,o=t.value;return o=o.charAt(0).toUpperCase()+o.slice(1),o.length<=0?void(r.innerHTML=""):(window.addEventListener("AjaxComplete",function(){e=i.fetch(),a.parentNode.appendChild(r),r.innerHTML="";for(var t=0;t<e.length;t++)n=x(e,t),n.addEventListener("click",E,!1),r.appendChild(n)}),void i.fetchFriendsByName(o))},x=function(t,e){m_result=t,m_index=e;var n=document.createElement("div"),i=document.createElement("img"),a=document.createElement("span"),r=document.createElement("span");return i.setAttribute("src",APP.DOMAIN+"/assets/img/uploads/"+m_result[m_index].avatar),a.className="avatar avatar-xs is-circle spanicon",a.appendChild(i),r.innerHTML=m_result[m_index].name,n.setAttribute("data-userid",m_result[m_index].id),n.className="invited-user flex flex-vcenter",n.appendChild(a),n.appendChild(r),n},S=function(){var t=document.createElement("div"),e=-1;t.className="form-field";for(var r=0;r<v.length;r++)d.appendChild(v[r].getElement()),"description"===v[r].getRole()&&(e=r,c=r);for(var r=0;r<f.length;r++)t.appendChild(f[r].getElement());for(var r=0;r<h.length;r++)d.appendChild(h[r].getTimeWrapper());g(),m(),T(),d.classList.add("form"),d.appendChild(t),o.className="form-field",v[e].getElement().parentNode.insertBefore(o,v[e].getElement().nextSibling),n.appendChild(d),n.className="modal-form animated bounceInDown",a.appendChild(n),a.className="modal-wrapper",i.classList.add("modal-background"),document.body.insertBefore(i,document.body.firstChild),document.body.insertBefore(a,i)};S()}function Activity(t){"use strict";var e,n,i=t,a=this;this.getTimeValue=function(){var t=i.getStart();t=t.split(":");var e=t[0]+t[1];return parseInt(e)};var r=function(){var t=document.createElement("DIV");t.classList.add("activity"),e=t,o(),e.appendChild(n)},o=function(){var t=document.createElement("DIV");t.classList.add("monthTextBox"),1===i.getIsOwner()?t.classList.add("owner"):t.classList.add("invited"),t.innerHTML+='<div class="monthTimestamp">'+i.getStart()+"-"+i.getEnd()+"<div>",t.innerHTML+='<div class="monthTitle">'+i.getTitle()+"</div>",n=t};a.getElement=function(){return e},a.getId=function(){return i.getId()};var d=function(t){t.stopPropagation(),t.preventDefault(),1===i.getIsOwner()?window.dispatchEvent(new CustomEvent("UpdateActivity",{detail:i})):window.dispatchEvent(new CustomEvent("ViewActivity",{detail:i}))};r(),e.addEventListener("click",d,!1)}function Day(t,e,n){"use strict";var i,a,r,o=e,d=t,s=!1,c=[],l=this;r="undefined"!=typeof n&&n,this.setIsToday=function(t){t&&t!==r?(i.classList.add("isToday"),r=!0):t||t===r||(i.classList.remove("isToday"),r=!1)};var u=function(){c.sort(function(t,e){return t.getTimeValue()-e.getTimeValue()})},v=function(t){t&&t!==s?(i.classList.remove("empty"),i.classList.add("hasActivity"),s=!0):t||t===s||(i.classList.remove("hasActivity"),i.classList.add("empty"),s=!1)},f=function(){v(c.length>0?!0:!1)},h=function(){var t=document.createElement("DIV");t.classList.add("dayBox"),t.classList.add("empty"),r&&t.classList.add("isToday");var e=document.createElement("DIV");e.classList.add("dayNum"),a=e,g(),t.appendChild(e),i=t},g=function(){a.innerHTML=d.slice(-2)};this.getDate=function(){return d},this.getIndexOfId=function(t){for(var e=0;e<c.length;e++)if(t===c[e].getId())return e;return-1},this.addActivity=function(t){c.push(new Activity(t)),f(),u()},this.removeActivityById=function(t){for(var e=-1,n=0;n<c.length;n++)if(t===c[n].getId()){e=n;break}e!==-1&&(l.removeActivityByIndex(e),f())},this.removeActivityByIndex=function(t){o===c[t].getElement().parentNode&&o.removeChild(c[t].getElement());for(var e=t;e<c.length;e++)c[e]=c[e+1];c.pop(),f()},this.clearActivities=function(){for(var t=c.length-1;t>=0;t--)l.removeActivityByIndex(t);f()},this.getElement=function(){return i};var m=function(t){t.stopPropagation(),t.preventDefault(),o.innerHTML="",window.dispatchEvent(new CustomEvent("isViewing",{detail:d})),l.draw()};this.draw=function(){for(var t=0;t<c.length;t++)o.appendChild(c[t].getElement())},h(),i.addEventListener("click",m,!1)}function Month(t,e,n,i){"use strict";var a=[],r=[],o=0,d=[],s=[],c=0,l=t,u=e,v=i,f=n,h=this,g=-1,m=function(){"undefined"!=typeof v&&v.addEventListener("click",p,!1)},p=function(t){var e;e=g!==-1?a[g]:a[0];var n=new ActivityData("-1","-1","-1",e,"00:00","00:00","1");window.dispatchEvent(new CustomEvent("CreateActivity",{detail:n}))},y=function(){var t=a[0].slice(0,7),e=f.slice(0,7),n=parseInt(f.slice(-2))-1;t===e?d[n].setIsToday(!0):d[n].setIsToday(!1)},w=function(t){t.stopPropagation(),g!==-1&&d[g].getElement().classList.remove("isClicked"),g=parseInt(t.detail.slice(-2))-1,d[g].getElement().classList.add("isClicked")};this.clearActivities=function(){g!==-1&&d[g].getElement().classList.remove("isClicked");for(var t=0;t<d.length;t++)d[t].clearActivities()};var A=function(t){var e=t-o;if(e>0)for(var n=o;n<t;n++)l.insertBefore(r[n],l.firstChild);else if(e<0)for(var i=o-1;i>=t;i--)l.removeChild(r[i]);o=t},E=function(t){var e=t-c;if(e>0)for(var n=c;n<t;n++)l.insertBefore(s[n],l.lastChild.nextSibling);else if(e<0)for(var i=c-1;i>=t;i--)l.removeChild(s[i]);c=t},I=function(){var t=a.length-d.length;if(t>0)for(var e,n=0;n<t;n++){e=!1;var i=a[a.length-t];a[a.length-t]===f&&(e=!0),d.push(new Day(i,u,e)),l.insertBefore(d[d.length-1].getElement(),d[d.length-2].getElement().nextSibling)}else if(t<0)for(var r=d.length-1;r>=a.length;r--)l.removeChild(d[r].getElement()),d.pop()};this.setDates=function(t,e,n){a=t,d.length>0?(h.clearActivities(),I(),A(e),E(n),y()):(C(),D(),A(e),E(n))},this.addActivities=function(t){for(var e=0;e<t.length;e++)h.addActivity(t[e])},this.addActivity=function(t){var e=t.getDate().slice(-2),n=parseInt(e)-1;d[n].addActivity(t),n===g&&d[n].draw()},this.removeActivityById=function(t){for(var e=0;e<d.length;e++){var n=d[e].getIndexOfId(t);if(n!==-1){d[e].removeActivityByIndex(n);break}}},this.updateActivity=function(t){h.removeActivityById(t.getId());var e=L(t.getDate());e!==-1&&d[e].addActivity(t),e===g&&d[e].draw()};var L=function(t){for(var e=0;e<a.length;e++)if(a[e]===t)return e;return-1},D=function(){for(var t,e=0;e<7;e++)t=document.createElement("DIV"),t.classList.add("dayBox"),t.classList.add("deadDay"),r.push(t),t=document.createElement("DIV"),t.classList.add("dayBox"),t.classList.add("deadDay"),s.push(t)},C=function(){for(var t,e=0;e<a.length;e++)t=!1,a[e]===f&&(t=!0),d.push(new Day(a[e],u,t)),l.appendChild(d[e].getElement())};window.addEventListener("isViewing",w,!1),m()}function MonthMap(t){"use strict";var e,n,i=t,a=[];this.getDates=function(){return a},this.getLDC=function(){return e},this.getTDC=function(){return n};var r=function(){a=i.getMonthAsArray()},o=function(){i.setDate(1),e=(i.getDay()-1).mod(7)},d=function(){var t=7-(i.getNumOfDays()+e).mod(7);n=7===t?0:t};r(),o(),d()}function Notification(){var t,e=new Ajax,n=0,i=document.getElementById("userNotifier"),a=document.getElementById("notificationBell"),r=document.getElementById("notificationList"),o=!1,d=[];if("undefined"!=typeof i&&null!=i&&"undefined"!=typeof a&&null!=a&&"undefined"!=typeof r&&null!=r){r.addEventListener("click",function(t){t.stopPropagation();var i;i="I"===t.target.nodeName?t.target.parentNode:t.target,null!=typeof i&&"undefined"!=typeof i.dataset.index&&(e.answerNotification(d[i.dataset.index],i.dataset.action,"AnswerNotification"),d[i.dataset.index].hide,i.parentNode.parentNode.classList.add("hidden"),n--,document.getElementById("notificationCount").innerHTML=n,("accept"===i.dataset.action&&"3"===i.dataset.type||"4"===i.dataset.type)&&window.dispatchEvent(new CustomEvent("NotificationUpdate")))}),i.addEventListener("click",function(){o=!1,v(),e.setNotificationsToRead(),r.classList.contains("hidden")?r.classList.remove("hidden"):r.classList.add("hidden")});var s=function(){window.addEventListener("CheckNotificationsAjax",l),e.fetchCountNotifications("CheckNotificationsAjax")},c=function(){window.addEventListener("FetchNotificationsAjax",u),e.fetchNotifications("FetchNotificationsAjax")},l=function(){window.removeEventListener("CheckNotificationsAjax",l),t=e.fetch();var n=o;o=t.count>0,n!=o&&v(),window.setTimeout(function(){s()},5e3),c()},u=function(){window.removeEventListener("FetchNotificationsAjax",u),t=e.fetch(),r.innerHTML="",d=[],n=t.length,r.innerHTML+='<div class="notification-header">Notifications (<span id="notificationCount">'+t.length+"</span>)</div>";for(var i=0;i<t.length;i++){var a=new NotificationsItem(t[i],i);d.push(a),r.innerHTML+=a.draw()}r.innerHTML+='<div class="notification-footer"></div>'},v=function(){o===!0?a.setAttribute("style","color: #ffa500"):a.setAttribute("style","color: #cccccc")};s()}}function Converter(){"use strict";var t,e;this.timeToPercent=function(n){var a=n.split(":");t=parseInt(a[0]),e=parseInt(a[1]);var r=t+e/60;return i(r,0,24,0,100)},this.percentToTime=function(a,r,o){var d=a*(r/o);return t=Math.floor(d),d-=t,e=Math.round(i(d,0,1,0,60)),n()};var n=function(n){var i="";return i+=t<10?"0"+t:t,i+=":",i+=e<10?"0"+e:e},i=function(t,e,n,i,a){return parseFloat((t-e)*(a-i)/(n-e)+i)}}function Draggable(t,e,n,i,a,r){"use strict";var o,d,s,c,l,u=t,v=e,f=n,h=i,g=a,m=this,p=1,y=r,w=[],A=[],E=!1,I=!1,L=new Converter,D=document.getElementById("plannerMain").offsetTop;this.isMoving=!1,this.isSelected=!1,this.updateActivityTime=function(){var t=m.toTime(O()),e=m.toTime(this.getEndPos());t===v.getStart()&&e===v.getEnd()||v.updateTime(t,e)},this.setActivityData=function(t){v=t,m.transferActivityData()},this.getDataId=function(){return v.getId()},this.fromTime=function(t){return L.timeToPercent(t)},this.toTime=function(t){var e=U(t);return L.percentToTime(e,24,y)},this.transferActivityData=function(){var t=m.fromTime(v.getStart()),e=m.fromTime(v.getEnd())-t;c=v.getTitle(),1===v.getIsOwner()?l.classList.add("owner"):l.classList.add("invited"),P(t),k(e),m.updateTextBox()},this.isStreching=function(){return I||E},this.enableMoving=function(){m.isMoving=!0,u.style.zIndex=1},this.disableMoving=function(){m.isMoving=!1,u.style.zIndex=0},this.setIsMovingEvent=function(t){g=t},this.updateTextBox=function(){var t=m.toTime(O()),e=m.toTime(this.getEndPos());l.innerHTML='<div class="timestamp">'+t+"-"+e+"<div>",l.innerHTML+='<div class="title">'+c+"</div>"};var C=function(){var t=document.createElement("DIV");t.classList.add("textBox"),o.appendChild(t),l=t,m.updateTextBox()},T=function(){var t=document.createElement("DIV");t.classList.add("inner"),u.appendChild(t),o=t},M=function(){var t=document.createElement("DIV");t.classList.add("stretchable"),o.appendChild(t),d=t;var e=document.createElement("DIV");e.classList.add("stretchable"),o.appendChild(e),s=e};this.setGridSizeX=function(t){p=t,x()};var x=function(){w=[];for(var t=0;t<=p;t++)w.push(parseFloat(t*(100/p)))},S=function(){for(var t=0;t<=y;t++)A.push(parseFloat(t*(100/y)))},b=function(t){for(var e,n=101,i=0,a=0;a<w.length;a++)e=Math.abs(parseFloat(w[a]-t)),e<n&&(n=e,i=a);return w[i]},F=function(t){for(var e,n=101,i=0,a=0;a<A.length;a++)e=Math.abs(parseFloat(A[a]-t)),e<n&&(n=e,i=a);return A[i]},N=function(){return m.toPercentWidth(parseFloat(window.getComputedStyle(u).width))};this.getWidth=function(){return m.toPercentWidth(parseFloat(window.getComputedStyle(u).width))},this.getLeft=function(){return m.toPercentWidth(parseFloat(window.getComputedStyle(u).left))};var P=function(t){u.style.top=t+"%"},k=function(t){u.style.height=t+"%"},B=function(t){u.style.width=t+"%"},O=function(){return m.toPercentHeight(parseFloat(window.getComputedStyle(u).top))},H=function(){return m.toPercentHeight(parseFloat(window.getComputedStyle(u).height))};this.setLeft=function(t){u.style.left=t+"%"};var _=function(){k(F(O()+H())-O()),m.updateTextBox()},q=function(){B(b(m.getLeft()+N())-m.getLeft())},W=function(t){for(var e,n=101,i=0,a=0;a<w.length;a++)e=Math.abs(parseFloat(w[a]-t)),e<n&&(n=e,i=a);return i},U=function(t){for(var e,n=101,i=0,a=0;a<A.length;a++)e=Math.abs(parseFloat(A[a]-t)),e<n&&(n=e,i=a);return i},j=function(t){var e=W(t);return w[e-1]};this.snapToGridX=function(){var t=b(m.getLeft()+m.toPercentWidth(1));t>=100?m.setLeft(j(t)):m.setLeft(t),q()},this.snapToGridY=function(){P(F(O())+m.toPercentHeight(1)),_()},this.getStartPos=function(){return this.toPercentHeight(parseFloat(window.getComputedStyle(u).top))},this.getEndPos=function(){return this.getStartPos()+this.toPercentHeight(parseFloat(window.getComputedStyle(u).height))},this.setElement=function(t){u=t},this.getElement=function(){return u},this.setParentHeight=function(t){h=t},this.toPercentWidth=function(t){var e=0,n=f,i=0,a=100;return parseFloat((t-e)*(a-i)/(n-e)+i)},this.toPercentHeight=function(t){var e=0,n=h,i=0,a=100;return parseFloat((t-e)*(a-i)/(n-e)+i)},this.toPixelsWidth=function(t){var e=0,n=100,i=0,a=f;return parseFloat((t-e)*(a-i)/(n-e)+i)},this.toPixelsHeight=function(t){var e=0,n=100,i=0,a=h;return parseFloat((t-e)*(a-i)/(n-e)+i)};var R=function(t){t.stopPropagation(),t.preventDefault(),m.enableMoving();var e=parseFloat(window.getComputedStyle(this).left),n=parseFloat(window.getComputedStyle(this).top),i=m.toPercentWidth(t.clientX),a=m.toPercentHeight(t.pageY),r=m.toPercentHeight(t.pageY-D),o=m.toPercentHeight(parseFloat(window.getComputedStyle(d).height)),c=m.toPercentHeight(parseFloat(window.getComputedStyle(s).height));r>=O()&&r<=O()+o?(I=!0,E=!1):r>=m.getEndPos()-c?(E=!0,I=!1):(I=!1,E=!1);var l=function(t){var r=m.toPercentWidth(e+t.clientX)-i,o=m.toPercentHeight(n+t.pageY)-a;m.setLeft(r),o>=0&&o+H()<=100&&F(o)!==F(O())&&(P(o),m.snapToGridY()),document.dispatchEvent(g),t.stopPropagation()},u=function(t){m.snapToGridX(),m.disableMoving(),document.removeEventListener("mouseup",u,!0),document.removeEventListener("mousemove",l,!0),t.stopPropagation(),m.updateActivityTime()},v=function(t){if(I){var e=O(),n=m.toPercentHeight(t.pageY-D)-e,i=e+n,a=m.getEndPos()-F(i);i<m.getEndPos()-100/y&&F(i)!==F(e)&&(P(i),k(a),m.snapToGridY(),document.dispatchEvent(g)),t.stopPropagation()}},f=function(t){I&&(m.snapToGridX(),I=!1,m.disableMoving(),document.removeEventListener("mouseup",v,!0),document.removeEventListener("mousemove",f,!0),t.stopPropagation(),m.updateActivityTime())},h=function(t){var e=O(),n=m.toPercentHeight(t.pageY-D)-e,i=n+e;i>e+100/y&&i<=100&&F(i)!==F(m.getEndPos())&&(k(n),m.snapToGridY(),document.dispatchEvent(g)),t.stopPropagation()},p=function(t){m.snapToGridX(),E=!1,m.disableMoving(),document.removeEventListener("mousemove",h,!0),document.removeEventListener("mouseup",p,!0),t.stopPropagation(),m.updateActivityTime()};I?(document.addEventListener("mousemove",v,!0),document.addEventListener("mouseup",f,!0)):E?(document.addEventListener("mousemove",h,!0),document.addEventListener("mouseup",p,!0)):(document.addEventListener("mousemove",l,!0),document.addEventListener("mouseup",u,!0))},V=function(t){t.stopPropagation(),t.preventDefault(),1===v.getIsOwner()?window.dispatchEvent(new CustomEvent("UpdateActivity",{detail:v})):window.dispatchEvent(new CustomEvent("ViewActivity",{detail:v}))};S(),T(),C(),M(),this.transferActivityData(),this.updateTextBox(),this.snapToGridY(),this.disableMoving(),1===v.getIsOwner()&&u.addEventListener("mousedown",R,!1),u.addEventListener("dblclick",V,!1)}function Collision(t){"use strict";var e=[];this.hasBeendAdded=!1;var n=function(){e.sort(function(t,e){return t-e})};if("object"==typeof t){for(var i=0;i<t.length;i++)e.push(t[i]);n()}else e.push(t);this.getFirstCI=function(){return e>0?e[0]:"CI is empty"},this.addCollindingIndex=function(t){a(t)===!1&&(e.push(t),n())},this.getCollidingIndices=function(){return e},this.addOther=function(t){for(var i=0;i<t.getCollidingIndices().length;i++){for(var a=!1,r=0;r<e.length;r++)if(t.getCollidingIndices()[i]===e[r]){a=!0;break}a===!1&&e.push(t.getCollidingIndices()[i])}n()},this.shareCommonIndex=function(t){for(var n=!1,i=0;i<t.getCollidingIndices().length;i++){for(var a=0;a<e.length;a++)if(t.getCollidingIndices()[i]===e[a]){n=!0;break}if(n===!0)break}return n};var a=function(t){for(var n=0;n<e.length;n++)if(e[n]===t)return!0;return!1},r=function(t){for(var n,i=0;i<e.length;i++)if(e[i]===t){n=i;break}return n};this.getString=function(){for(var t="[",n=0;n<e.length;n++)n>0&&(t+=","),t+=e[n].toString();return t+="]"},this.clearCollision=function(){for(var t=e.length,n=0;n<t;n++)e.pop()},this.addCollindingIndexWithoutSort=function(t){a(t)===!1&&e.push(t)},this.removeCollidingIndex=function(t){if(a(t)){for(var n=r(t),i=n;i<e.length-1;i++)e[i]=e[i+1];e.pop()}},this.insertBefore=function(t,n){if(a(n)){var i=r(n);e.push(-2);for(var o=e.length-1;o>i;o--)e[o]=e[o-1];e[i]=t}},this.insertAfter=function(t,n){if(a(n)){var i=r(n);e.push(-2);for(var o=e.length-1;o>i;o--)e[o]=e[o-1];e[i+1]=t}}}function Column(t,e){"use strict";var n,i,a,r=t,o=e,d=[],s=[],c=0,l=0,u=this,v=null,f=null,h=null,g=[],m=function(t){for(var e,n=101,i=0,a=0;a<g.length;a++)e=Math.abs(parseFloat(g[a]-t)),e<n&&(n=e,i=a);return i};this.toPercentHeight=function(t){var e=0,n=l,i=0,a=100;return parseFloat((t-e)*(a-i)/(n-e)+i)};var p=function(t){for(var e,n=101,i=0,a=0;a<g.length;a++)e=Math.abs(parseFloat(g[a]-t)),e<n&&(n=e,i=a);return i>=1&&i--,g[i]},y=function(){for(var t=0;t<=o;t++)g.push(parseFloat(t*(100/o)))};this.clearActivities=function(){for(var t=s.length-1;t>=0;t--)r.removeChild(s[t].getElement()),s.pop(),d.pop();s=[],d=[]},this.getDate=function(){return a},this.updateActivity=function(t){var e=w(t.getId());d[e]=t,s[u.getIndexOfCorrenspondingItem(t.getId())].setActivityData(t)},this.hasId=function(t){for(var e=0;e<d.length;e++)if(t===d[e].getId())return!0;return!1};var w=function(t){for(var e=0;e<d.length;e++)if(t===d[e].getId())return e;return null};this.removeActivityById=function(t){u.removeItemByIndex(u.getIndexOfCorrenspondingItem(t)),u.removeDataItemByIndex(w(t)),v=null,u.manageCollisions()},this.setDate=function(t){a=t},this.addItemFromOther=function(t){r.appendChild(t.getElement()),t.setIsMovingEvent(n),s.push(t),t.disableMoving(),v=null,t.transferActivityData(),u.manageCollisions()},this.addDataItemFromOther=function(t){t.setDate(a),d.push(t),window.dispatchEvent(new CustomEvent("ActivityDrop",{detail:t}))},this.removeItemByIndex=function(t){if(!(t<0||t>=s.length)){r.removeChild(s[t].getElement());for(var e=t;e<s.length;e++)s[e]=s[e+1];s.pop()}},this.removeDataItemByIndex=function(t){if(!(t<0||t>=d.length)){for(var e=t;e<d.length;e++)d[e]=d[e+1];d.pop()}};var A=function(t){if("undefined"==typeof f)return"Prev is null!";var e=s[t],n=I(s[t]);f.addDataItemFromOther(d[n]),u.removeItemByIndex(t),f.addItemFromOther(e),u.removeDataItemByIndex(n),v=null,u.manageCollisions()},E=function(t){if("undefined"==typeof h)return"Next is null!";var e=s[t],n=I(s[t]);h.addDataItemFromOther(d[n]),u.removeItemByIndex(t),h.addItemFromOther(e),u.removeDataItemByIndex(n),v=null,u.manageCollisions()};this.sendActivityToOther=function(t,e){if("undefined"==typeof h)return"Next is null!";var n=s[t],i=I(s[t]);e.addDataItemFromOther(d[i]),u.removeItemByIndex(t),e.addItemFromOther(n),u.removeDataItemByIndex(i),v=null},this.getIndexOfCorrenspondingItem=function(t){for(var e=0;e<s.length;e++)if(t===s[e].getDataId())return e;return null};var I=function(t){for(var e=t.getDataId(),n=0;n<d.length;n++)if(e===d[n].getId())return n;return null};this.setPrev=function(t){f=t},this.setNext=function(t){h=t},this.getPrev=function(){return null===f?"Prev is null!":f},this.getNext=function(){return null===h?"Next is null!":h},this.removePrev=function(){f=null},this.removeNext=function(){h=null};var L=function(t){for(var e=[],n=0;n<t.length;n++)if(t[n].hasBeendAdded===!1){var i=new Collision(t[n].getCollidingIndices());t[n].hasBeendAdded=!0;for(var a=0;a<t.length;a++)i.shareCommonIndex(t[a])===!0&&t[a].hasBeendAdded===!1&&(i.addOther(t[a]),t[a].hasBeendAdded=!0);e.push(i)}return e},D=function(){if("undefined"!=typeof s){for(var t,e=[],n=0;n<s.length;n++){t=new Collision(n);for(var a=0;a<s.length;a++)(s[n].getStartPos()<=s[a].getEndPos()&&s[n].getStartPos()>=s[a].getStartPos()||s[n].getEndPos()<=s[a].getEndPos()&&s[n].getEndPos()>=s[a].getStartPos())&&t.addCollindingIndex(a);var r=!1;if("undefined"!=typeof e)for(var o=0;o<e.length;o++)if(e[o].getString()===t.getString()){r=!0;break}r===!1&&e.push(t)}i=L(e)}},C=function(t){for(var e=0;e<i.length;e++)for(var n=i[e].getCollidingIndices(),a=0;a<n.length;a++)s[n[a]].setGridSizeX(n.length),s[n[a]].getElement().style.width=100/n.length+"%",t!==n[a]&&(s[n[a]].getElement().style.left=a*(100/n.length)+"%")};this.manageCollisions=function(){s.sort(function(t,e){return t.getLeft()===e.getLeft()?0:t.getLeft()<e.getLeft()?-1:1});for(var t=0;t<s.length;t++)if(s[t].isMoving){v=t;break}if(null!==v&&(s[v].isStreching()?r.style.overflow="hidden":(r.style.overflow="visible",s[v].getLeft()+s[v].getWidth()/2>=100?null===h?s[v].snapToGridX():E(v):s[v].getLeft()<=-(s[v].getWidth()/2)&&(null===f?s[v].snapToGridX():A(v)))),D(),null!==v){for(var e,n=0;n<i.length;n++)for(var a=0;a<i[n].getCollidingIndices().length;a++)if(i[n].getCollidingIndices()[a]===v){e=n;break}var o,d=!1,c=i[e];c.removeCollidingIndex(v);for(var l=0;l<c.getCollidingIndices().length;l++){if(o=c.getCollidingIndices()[l],s[v].getLeft()+s[v].getWidth()>=s[o].getLeft()+s[o].getWidth()/2&&s[v].getLeft()<=s[o].getLeft()){c.insertAfter(v,o),v=null,d=!0;break}if(s[v].getLeft()<=s[o].getLeft()+s[o].getWidth()/2&&s[v].getLeft()+s[v].getWidth()>=s[o].getLeft()+s[o].getWidth()){c.insertBefore(v,o),v=null,d=!0;break}}d?i[e]=c:i[e].addCollindingIndex(v)}C(v)};var T=function(t){t.receiver===r.getAttribute("id")&&u.manageCollisions()};this.updateWidth=function(){c=parseFloat(window.getComputedStyle(r).width)},this.updateHeight=function(){l=parseFloat(window.getComputedStyle(r).height)},this.getElement=function(){return r},this.setElement=function(t){r=t},this.getItems=function(){return s};var M=function(){for(var t=0;t<o;t++){var e=document.createElement("div");e.classList.add("cell"),e.style.height=l/o+"px",r.appendChild(e)}};this.addActivity=function(t){d.push(t);var e=document.createElement("DIV");e.classList.add("draggable"),e.classList.add("activity"),r.appendChild(e),s.push(new Draggable(e,t,c,l,n,o)),u.manageCollisions()},n=new Event("isMoving"),n.receiver=r.getAttribute("id"),document.addEventListener("isMoving",T,!1),this.updateWidth(),this.updateHeight(),M(),y(),this.getTimeOfMouse=function(t){var e=document.getElementById("plannerMain").offsetTop,n=t-e,i=new Converter;return i.percentToTime(m(p(u.toPercentHeight(n))),24,o)};var x=function(t){var e=u.getTimeOfMouse(t.pageY),n=new ActivityData("null","null","null",a,e,e,1);window.dispatchEvent(new CustomEvent("CreateActivity",{detail:n}))};r.addEventListener("dblclick",x,!1)}function ActivityData(t,e,n,i,a,r,o,d){"use strict";var s=t,c=e,l=n,u=i,v=a,f=r,h=parseInt(o);"undefined"==typeof d&&(d=[]);var g=d,m=this;this.getId=function(){return s},this.getInvited=function(){return g},this.getTitle=function(){
return c},this.getDescription=function(){return l},this.getStart=function(){return v},this.getDate=function(){return u},this.getEnd=function(){return f},this.setDate=function(t){u=t},this.setStart=function(t){v=t},this.setEnd=function(t){f=t},this.getString=function(){var t="";return t+='"id":"'+s+'",',t+='"title":"'+c+'",',t+='"description":"'+l+'",',t+='"date":"'+u+'",',t+='"start":"'+v+'",',t+='"end":"'+f+'"',t+='"isOwner":"'+h+'"',t+='"invited":"',t+=g.toString(),t+='"'},this.getAjaxFormat=function(){var t={};return t.id=m.getId(),t.title=m.getTitle(),t.description=m.getDescription(),t.date=m.getDate(),t.activity_start=m.getDate()+" "+m.getStart(),t.activity_end=m.getDate()+" "+m.getEnd(),t.isOwner=m.getIsOwner(),t.invited_str="",m.getInvited().length>0&&(t.invited_str=m.getInvited().toString()),t},this.updateTime=function(t,e){v=t,f=e,window.dispatchEvent(new CustomEvent("ActivityDrop",{detail:m}))},this.getIsOwner=function(){return h}}function Week(t,e){"use strict";var n=t,i=[],a=[],r=e,o=this;this.clearActivities=function(){for(var t=0;t<i.length;t++)i[t].clearActivities()},this.getIndexOfDate=function(t){for(var e=0;e<a.length;e++)if(t===a[e])return e;return-1},this.updateActivity=function(t){for(var e=-1,n=0;n<i.length;n++)if(i[n].hasId(t.getId())){e=n;break}if(e!==-1)if(t.getDate()===i[e].getDate())i[e].updateActivity(t);else if(o.getIndexOfDate(t.getDate())!==-1){var a=i[e].getIndexOfCorrenspondingItem(t.getId());i[e].updateActivity(t),i[e].sendActivityToOther(a,i[o.getIndexOfDate(t.getDate())])}else i[e].removeActivityById(t.getId())},this.setDates=function(t){i.length>0?o.clearActivities():d(),a=t;for(var e=0;e<7;e++)i[e].setDate(a[e])},this.addActivity=function(t){for(var e=-1,n=0;n<a.length;n++)if(t.getDate()===a[n]){e=n;break}e!==-1&&i[e].addActivity(t)},this.addActivities=function(t){for(var e=0;e<t.length;e++)this.addActivity(t[e])};var d=function(){for(var t=0;t<7;t++){var e=document.createElement("DIV");e.classList.add("weekday"),n.appendChild(e),i.push(new Column(e,r))}for(var a=0;a<7;a++)0!==t&&i[a].setPrev(i[a-1]),6!==t&&i[a].setNext(i[a+1])};this.removeActivityById=function(t){for(var e=0;e<i.length;e++)if(i[e].hasId(t)){i[e].removeActivityById(t);break}}}function validate(t){var e=!0;if("friendForm"===t.target.id){var n={email:document.getElementsByName("email")[0]};for(var i in n)""===n[i].value?(n[i].classList.add("form-error"),e=!1):n[i].classList.remove("form-error")}if("loginForm"===t.target.id){var a={email:document.getElementsByName("email")[0],password:document.getElementsByName("password")[0]};for(var i in a)""===a[i].value?(a[i].classList.add("form-error"),e=!1):a[i].classList.remove("form-error")}if("registerForm"===t.target.id){var r={email:document.getElementsByName("email")[0],password:document.getElementsByName("password")[0],passwordRepeat:document.getElementsByName("passwordRepeat")[0],fname:document.getElementsByName("fname")[0],lname:document.getElementsByName("lname")[0]};for(var i in r)""===r[i].value?(r[i].classList.add("form-error"),e=!1):r[i].classList.remove("form-error")}e||t.preventDefault()}Number.prototype.mod=function(t){"use strict";return(this%t+t)%t},Date.prototype.getNumOfDays=function(){"use strict";var t=new Date(this.getFullYear(),this.getMonth()+1,0);return t.getDate()},Date.prototype.getMonthAsArray=function(){"use strict";for(var t=[],e=0;e<this.getNumOfDays();e++)t.push(this.getFullYear()+"-"+(this.getMonth()+1)+"-"+("0"+(e+1)).slice(-2));return t},Date.prototype.getFirstDayOfWeek=function(){"use strict";var t=new Date(this.getTime()),e=(t.getDay()-1).mod(7);return new Date(this.getTime()-864e5*e)},Date.prototype.getWeekAsArray=function(){"use strict";for(var t=new Date(this.getFirstDayOfWeek()),e=[],n=0;n<7;n++)e.push(t.getFullYear()+"-"+(t.getMonth()+1)+"-"+("0"+t.getDate()).slice(-2)),t.setDate(t.getDate()+1);return e},Date.prototype.getDayName=function(){"use strict";var t=["SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY"];return t[this.getDay()]},Date.prototype.getDayShortName=function(){"use strict";var t=["SUN","MON","TUE","WED","THU","FRI","SAT"];return t[this.getDay()]},Date.prototype.getMonthName=function(t){"use strict";var e=["January","February","March","April","May","June","July","August","September","October","November","December"];return t==e.length&&(t=0),e[t]},Date.prototype.getFullDateString=function(){"use strict";var t=this.getFullYear(),e=this.getMonth()+1,n=this.getDate();return n<10&&(n="0"+n),t+"-"+e+"-"+n},String.prototype.format||(String.prototype.format=function(){var t=arguments;return this.replace(/{(\d+)}/g,function(e,n){return"undefined"!=typeof t[n]?t[n]:e})});var NotificationsItem=function(t,e){var n=e,i=t.id,a=t.type,r=t.initiator_name,o="",d="",s=t.content,c=t.category,l=!0;"3"!==a&&"4"!==a&&"5"!==a||(o=t.activity_name,d=t.activity_id);this.draw=function(){if(l){var t='<div class="fs-xs notification-item">';return"question"===c?(t+="1"===a?'<div class="description">'+s.format(r)+"</div>":'<div class="description">'+s.format(r,o)+"</div>",t+='<div class="notification-action"><div class="action" data-id="notification-decline" data-action="decline" data-index="'+n+'" data-type="'+a+'" data-notification="'+i+'"><i class="fa fa-times decline" aria-hidden="true"></i></div>',t+='<div class="action" data-id="notification-confirm" data-action="accept" data-index="'+n+'" data-type="'+a+'" data-notification="'+i+'"><i class="fa fa-check accept" aria-hidden="true"></i></div></div>'):(t+="2"===a?'<div class="description">'+s.format(r)+"</div>":"5"===a?'<div class="description">'+s.format(r)+"</div>":'<div class="description">'+s.format(o)+"</div>",t+='<div class="notification-action">',t+='<div class="action" data-id="notification-decline" data-action="accept" data-type="'+a+'" data-index="'+n+'" data-notification="'+i+'"><i class="fa fa-check accept" aria-hidden="true"></i></div></div>'),t+="</div>"}},this.getNotificationId=function(){return i},this.hide=function(){l=!1}},Planner=function(t,e,n,i){"use strict";var a,r=this,o=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];this.week,this.month,this.ajax=new Ajax;var d,s,c,l,u=!0,v=!1,f=function(){"undefined"!=typeof t&&(d=document.querySelector(t),null!==d&&(u?d.addEventListener("click",w):d.addEventListener("click",I))),"undefined"!=typeof e&&(s=document.querySelector(e),null!==s&&(u?s.addEventListener("click",y):s.addEventListener("click",A))),"undefined"!=typeof n&&(c=document.querySelector(n),null!==c&&(u?c.addEventListener("click",p):c.addEventListener("click",E))),"undefined"!=typeof i&&(l=document.querySelector(i)),null!==d&&null!==s&&null!==c&&null!==l&&(v=!0)},h=function(){var t=r.ajax.fetch(),e=[];if(null!==t.invited)for(var n=0;n<t.invited.length;n++)e[n]=t.invited[n].id;var i=new ActivityData(t.id,t.title,t.description,t.timestart.substring(0,10),("0"+t.timestart).slice(-5),("0"+t.timeend).slice(-5),t.isOwner,e);u?r.week.updateActivity(i):r.month.updateActivity(i),window.removeEventListener("AC-UA",h)},g=function(){var t=r.ajax.fetch(),e=[];if(null!==t.invited)for(var n=0;n<t.invited.length;n++)e.push(t.invited[n].id);var i=new ActivityData(t.id,t.title,t.description,t.date,("0"+t.timestart).slice(-5),("0"+t.timeend).slice(-5),t.isOwner,e);u?r.week.addActivity(i):r.month.addActivity(i),window.removeEventListener("AC-CA",g)},m=function(){for(var t=r.ajax.fetch(),e=new Array,n=0;n<t.length;n++){var i=[];null!==t[n].invited&&i.push(t[n].invited.split(","));var a=new ActivityData(t[n].id,t[n].title,t[n].description,t[n].date,("0"+t[n].timestart).slice(-5),("0"+t[n].timeend).slice(-5),t[n].owner,i);e.push(a)}u?r.week.addActivities(e):r.month.addActivities(e),window.removeEventListener("AC-AA",m)},p=function(){a.setDate(a.getDate()+7),r.resetWeek(a.getWeekAsArray())},y=function(){a=new Date;var t=a.getWeekAsArray();r.resetWeek(t)},w=function(){a.setDate(a.getDate()-7),r.resetWeek(a.getWeekAsArray())},A=function(){a=new Date;var t=new MonthMap(a);r.resetMonth(t.getDates(),t.getLDC(),t.getTDC())},E=function(){a.setMonth(a.getMonth()+1);var t=new MonthMap(a);r.resetMonth(t.getDates(),t.getLDC(),t.getTDC())},I=function(){a.setMonth(a.getMonth()-1);var t=new MonthMap(a);r.resetMonth(t.getDates(),t.getLDC(),t.getTDC())},L=function(t){for(var e=new Date,n=document.querySelectorAll(".weekday"),i=0;i<n.length;i++)n[i].classList.remove("today");for(var i=0;i<t.length;i++)if(e.toJSON().slice(0,10)==t[i])for(var a=document.querySelectorAll(".weekday:nth-of-type("+(i+1)+")"),r=0;r<a.length;r++)a[r].classList.add("today")};this.setTitle=function(t){var e=document.getElementById("plannerHeading");e.innerHTML=a.getFullYear()+" "+a.getMonthName(a.getMonth()),t[t.length-1].slice(-2)<t[0].slice(-2)&&(e.innerHTML+=" - ",e.innerHTML+=a.getMonthName(a.getMonth()+1))},this.resetWeek=function(t){var e=(new Date(t[0]),document.getElementById("plannerWeekDays"));if(r.setTitle(t),null!==e){e.innerHTML="";for(var n=0;n<7;n++)e.innerHTML+='<div class="pull-left weekday"><span>'+t[n].slice(-2)+" "+o[n]+"</span></div>"}r.week.setDates(t),window.addEventListener("AC-AA",m),r.ajax.fetchActivitiesByDate(t[0],t[t.length-1],"AC-AA"),null!==e&&L(t)},this.createUpdateModal=function(t){var e=new FormMap;e.addButton("Update","update","spanicon btn btn-sm btn-primary"),e.addButton("Close","cancel","btn btn-sm btn-default"),e.addButton("Delete Activity","delete","pull-right btn btn-sm btn-danger"),e.addInput("Title","title","text",t.detail.getTitle()),e.addInput("Description","description","textarea",t.detail.getDescription()),e.addTime("Date","date",t.detail.getDate()),e.addTime("Start","start",t.detail.getStart()),e.addTime("End","end",t.detail.getEnd()),e.addInput("Add a friend?","friend-field","text");new Modal(e,t.detail);window.removeEventListener("UpdateActivity",r.createUpdateModal),window.addEventListener("UpdateActivity",r.updateFromModal),location.assign("#header")},this.createActivityModal=function(t){var e=new FormMap;e.addButton("Submit","submit","spanicon btn btn-sm btn-primary"),e.addButton("Close","cancel","btn btn-sm btn-default"),e.addInput("Title","title","text"),e.addInput("Description","description","textarea"),e.addTime("Date","date",t.detail.getDate()),e.addTime("Start","start",t.detail.getStart()),e.addTime("End","end",t.detail.getEnd()),e.addInput("Add a friend?","friend-field","text");new Modal(e);window.removeEventListener("CreateActivity",r.createActivityModal),window.addEventListener("CreateActivity",r.createFromModal),location.assign("#header")},this.createFromModal=function(t){window.addEventListener("AC-CA",g),r.ajax.createActivity(t.detail.getAjaxFormat(),"AC-CA"),window.removeEventListener("CreateActivity",r.createFromModal),window.addEventListener("CreateActivity",r.createActivityModal)},this.updateFromModal=function(t){window.addEventListener("AC-UA",h),r.ajax.updateActivity(t.detail.getAjaxFormat(),"AC-UA"),window.removeEventListener("UpdateActivity",r.updateFromModal),window.addEventListener("UpdateActivity",r.createUpdateModal)},this.deleteActivityFromView=function(t){var e=r.ajax.fetch();u?r.week.removeActivityById(e.activity_id):r.month.removeActivityById(e.activity_id),window.removeEventListener("AC-DA",r.deleteActivityFromView)},this.viewActivityModal=function(t){var e=new FormMap;e.addButton("Opt-out","decline","btn btn-sm btn-danger spanicon"),e.addButton("Close","cancel","btn btn-sm btn-default"),e.addInput("Title","title","text",t.detail.getTitle()),e.addInput("Description","description","textarea",t.detail.getDescription()),e.addTime("Date","date",t.detail.getDate()),e.addTime("Start","start",t.detail.getStart()),e.addTime("End","end",t.detail.getEnd());var n=new Modal(e,t.detail);n.disableInput(),location.assign("#header")},this.deleteActivity=function(t){window.addEventListener("AC-DA",r.deleteActivityFromView),r.ajax.deleteActivity(t.detail.getId(),"AC-DA")},this.declineActivity=function(t){window.addEventListener("AC-DA",r.deleteActivityFromView),r.ajax.declineActivityInvite(t.detail.getId(),"AC-DA")},this.closeForm=function(t){window.addEventListener("CreateActivity",r.createActivityModal),window.removeEventListener("CreateActivity",r.createFromModal),window.removeEventListener("UpdateActivity",r.updateFromModal),window.addEventListener("UpdateActivity",r.createUpdateModal)},this.createWeek=function(t,e){if(r.isWeek=!0,f(),v){r.week=new Week(document.querySelector(t),e),a=new Date;var n=a.getWeekAsArray();r.resetWeek(n),window.addEventListener("UpdateActivity",r.createUpdateModal),window.addEventListener("CreateActivity",r.createActivityModal),window.addEventListener("DeleteActivity",r.deleteActivity),window.addEventListener("CloseForm",r.closeForm),window.addEventListener("ViewActivity",r.viewActivityModal),window.addEventListener("DeclineActivity",r.declineActivity)}},this.resetMonth=function(t,e,n){r.setTitle(t),r.month.setDates(t,e,n),window.addEventListener("AC-AA",m),r.ajax.fetchActivitiesByDate(t[0],t[t.length-1],"AC-AA")},this.createMonth=function(t,e){if(u=!1,f(),v){a=new Date,r.month=new Month(document.querySelector(t),document.querySelector(e),a.getFullDateString(),l);var n=new MonthMap(a);r.resetMonth(n.getDates(),n.getLDC(),n.getTDC()),window.addEventListener("UpdateActivity",r.createUpdateModal),window.addEventListener("CreateActivity",r.createActivityModal),window.addEventListener("DeleteActivity",r.deleteActivity),window.addEventListener("CloseForm",r.closeForm),window.addEventListener("ViewActivity",r.viewActivityModal),window.addEventListener("DeclineActivity",r.declineActivity)}},window.addEventListener("ActivityDrop",function(t){r.ajax.updateActivity(t.detail.getAjaxFormat())}),window.addEventListener("NotificationUpdate",function(){if(u)r.resetWeek(a.getWeekAsArray());else{var t=new MonthMap(a);r.resetMonth(t.getDates(),t.getLDC(),t.getTDC())}})};"Desktop"==APP.USER_AGENT&&$(document).ready(function(){$("#userMenu > a").on("mouseover",function(){$("#userMenu").children(".sub-menu").fadeIn(300)}),$("#userMenu").on("mouseleave",function(){$(this).children(".sub-menu").fadeOut(300)})});var main=function(){var t=document.querySelector(".flash-close");null!=t&&t.addEventListener("click",function(){t.parentNode.classList.add("hidden")});for(var e=document.querySelectorAll("form"),n=0;n<e.length;n++)e[n].addEventListener("submit",validate,!1);if("Desktop"==APP.USER_AGENT){if("planner"==APP.CURRENT_PAGE){var i=new Planner("#previous","#current","#next","#add");"week"==APP.MODE?i.createWeek("#plannerContent",96):"month"==APP.MODE&&i.createMonth("#plannerMonthGrid","#plannerMonthDayInfo")}}else{var a=document.querySelector('[data-group="toggleDropdown"][data-role="toggle"]'),r=document.querySelector('[data-group="toggleDropdown"][data-role="target"]'),o=document.querySelector('[data-group="toggleNotifications"][data-role="toggle"]'),d=document.querySelector('[data-group="toggleNotifications"][data-role="target"]');if(null!=r&&null!=a&&a.addEventListener("click",function(){d.classList.add("hidden"),r.classList.contains("hidden")?r.classList.remove("hidden"):r.classList.add("hidden")}),null!=o&&null!=d&&o.addEventListener("click",function(){r.classList.add("hidden")}),"planner"==APP.CURRENT_PAGE){var i=new Planner("#previous","#current","#next","#add");i.createMonth("#plannerMonthGrid","#plannerMonthDayInfo")}}new Notification;"settings"==APP.CURRENT_PAGE&&(document.querySelector(".form-upload").addEventListener("click",function(){this.querySelector('input[type="file"]').click()}),document.querySelector('.form-upload input[type="file"]').addEventListener("change",function(){""==this.value?this.previousElementSibling.innerHTML="Click to upload":this.previousElementSibling.innerHTML=this.value.split("\\").pop()}))};window.addEventListener("load",main,!1);