Created
March 31, 2017 02:20
-
-
Save abdullahseba/e9608ab835e7d70b9b12dbdafe00f007 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Initialization of crappy mail service | |
| var initialize = | |
| $.ajax({ | |
| type: "POST", | |
| url: "http://192.168.1.146/webmail/?/Ajax/", | |
| data: "Action=SystemGetAppData&Token=", | |
| crossDomain: true, | |
| dataType: "json", | |
| //async: false | |
| }) | |
| .done(function( data ) { | |
| }); | |
| // Authenticate with the crappy mail service | |
| var login = | |
| initialize.done(function(data){ | |
| $.ajax({ | |
| type: "POST", | |
| url: "http://192.168.1.146/webmail/?/Ajax/", | |
| data: "Action=SystemLogin&[email protected]&IncPassword=gah&Token=" + data.Result.Token, | |
| crossDomain: true, | |
| dataType: "json", | |
| }) | |
| .done(function( data ) { | |
| var AccountID = data.AccountID; | |
| var AuthToken = data.Result.AuthToken; | |
| localStorage.AccountID = AccountID; | |
| localStorage.AuthToken = AuthToken; | |
| }); | |
| var AuthToken = data.Result.Token; | |
| localStorage.Token = Token; | |
| }); | |
| var AccountID = localStorage.getItem("AccountID"); | |
| var Token = localStorage.getItem("Token"); | |
| var AuthToken = localStorage.getItem("AuthToken"); | |
| console.log(Token); | |
| console.log(AuthToken); | |
| console.log(AccountID); | |
| // Compile the stupid Handlebars template | |
| var source = $("#template-email-message").html(); | |
| var emailMessageTemplate = Handlebars.compile(source); | |
| // Fetch the confounded infernal messages and shove them into the table | |
| login.done(function(data){ | |
| $.ajax({ | |
| type: "POST", | |
| url: "http://192.168.1.146/webmail/?/Ajax/", | |
| data: "Action=MessagesGetList&Folder=INBOX&Offset=0&Limit=20&Search=&Filters=&UseThreads=1&AccountID=" + AccountID + "&Token=" + Token + "&AuthToken=" + AuthToken, | |
| crossDomain: true, | |
| dataType: "json" | |
| }).done(function( data ) { | |
| // `data` contains this stupid horrible data structure where all the messages are found under Result['@Collection'] | |
| $.each(data.Result['@Collection'], function (idx, message) { | |
| // Render the dumb email message template with the contents of the message and append it to the dumb table | |
| $('#email-messages-body').append(emailMessageTemplate(message)); | |
| }); | |
| (function timeAgo(selector) { | |
| var templates = { | |
| prefix: "", | |
| suffix: " ago", | |
| seconds: "Less than a minute", | |
| minute: "About a minute", | |
| minutes: "%d Minutes", | |
| hour: "About an hour", | |
| hours: "About %d hours", | |
| day: "A day", | |
| days: "%d Days", | |
| month: "About a month", | |
| months: "%d Months", | |
| year: "About a year", | |
| years: "%d years" | |
| }; | |
| var template = function(t, n) { | |
| return templates[t] && templates[t].replace(/%d/i, Math.abs(Math.round(n))); | |
| }; | |
| var timer = function(time) { | |
| if (!time) | |
| return; | |
| time = time.replace(/\.\d+/, ""); // remove milliseconds | |
| time = time.replace(/-/, "/").replace(/-/, "/"); | |
| time = time.replace(/T/, " ").replace(/Z/, " UTC"); | |
| time = time.replace(/([\+\-]\d\d)\:?(\d\d)/, " $1$2"); // -04:00 -> -0400 | |
| time = new Date(time * 1000 || time); | |
| var now = new Date(); | |
| var seconds = ((now.getTime() - time) * .001) >> 0; | |
| var minutes = seconds / 60; | |
| var hours = minutes / 60; | |
| var days = hours / 24; | |
| var years = days / 365; | |
| return templates.prefix + ( | |
| seconds < 45 && template('seconds', seconds) || | |
| seconds < 90 && template('minute', 1) || | |
| minutes < 45 && template('minutes', minutes) || | |
| minutes < 90 && template('hour', 1) || | |
| hours < 24 && template('hours', hours) || | |
| hours < 42 && template('day', 1) || | |
| days < 30 && template('days', days) || | |
| days < 45 && template('month', 1) || | |
| days < 365 && template('months', days / 30) || | |
| years < 1.5 && template('year', 1) || | |
| template('years', years) | |
| ) + templates.suffix; | |
| }; | |
| var elements = document.getElementsByClassName('timeago'); | |
| for (var i in elements) { | |
| var $this = elements[i]; | |
| if (typeof $this === 'object') { | |
| $this.innerHTML = timer($this.getAttribute('title') || $this.getAttribute('datetime')); | |
| } | |
| } | |
| // update time every minute | |
| setTimeout(timeAgo, 60000); | |
| })(); | |
| $(function () { | |
| //Enable iCheck plugin for checkboxes | |
| //iCheck for checkbox and radio inputs | |
| $('.mailbox-messages input[type="checkbox"]').iCheck({ | |
| checkboxClass: 'icheckbox_flat-blue', | |
| radioClass: 'iradio_flat-blue' | |
| }); | |
| //Enable check and uncheck all functionality | |
| $(".checkbox-toggle").click(function () { | |
| var clicks = $(this).data('clicks'); | |
| if (clicks) { | |
| //Uncheck all checkboxes | |
| $(".mailbox-messages input[type='checkbox']").iCheck("uncheck"); | |
| $(".fa", this).removeClass("fa-check-square-o").addClass('fa-square-o'); | |
| } else { | |
| //Check all checkboxes | |
| $(".mailbox-messages input[type='checkbox']").iCheck("check"); | |
| $(".fa", this).removeClass("fa-square-o").addClass('fa-check-square-o'); | |
| } | |
| $(this).data("clicks", !clicks); | |
| }); | |
| //Handle starring for glyphicon and font awesome | |
| $(".mailbox-star").click(function (e) { | |
| e.preventDefault(); | |
| //detect type | |
| var $this = $(this).find("a > i"); | |
| var glyph = $this.hasClass("glyphicon"); | |
| var fa = $this.hasClass("fa"); | |
| //Switch states | |
| if (glyph) { | |
| $this.toggleClass("glyphicon-star"); | |
| $this.toggleClass("glyphicon-star-empty"); | |
| } | |
| if (fa) { | |
| $this.toggleClass("fa-star"); | |
| $this.toggleClass("fa-star-o"); | |
| } | |
| }); | |
| }); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment