Coverage

100% line coverage
100% statement coverage
100% block coverage
90 SLOC

lib/AlertController.js

100% line coverage
100% statement coverage
100% block coverage
17 SLOC
LineHitsStatementsSourceAction
1 not covered /* globals jQuery, alert */
21100%"use strict";
3 not covered
4 not covered /**
5 not covered * Controller to handle showing and hiding of server alert messages
6 not covered */
71100%var AlertController = function () {};
8 not covered
91100%AlertController.prototype = { /** * show the message * @param {String} html message * @return {AlertController} instance of this class for chaining */ show: function (html) {
10 not covered /**
11 not covered * show the message
12 not covered * @param {String} html message
13 not covered * @return {AlertController} instance of this class for chaining
14 not covered */
15 not covered show: function (html) {
161100% var me = this;
171100% me.message.html(html);
181100% me.container.addClass("showing");
191100% return me;
20 not covered },
21 not covered
22 not covered /**
23 not covered * hide the message
24 not covered * @return {AlertController} instance of this class for chaining
25 not covered */
26 not covered hide: function () {
271100% var me = this;
281100% me.container.removeClass("showing");
291100% return me;
30 not covered },
31 not covered
32 not covered /**
33 not covered * entry point into the controller, binds event listeners
34 not covered * @return {AlertController} instance of this class for chaining
35 not covered */
36 not covered bindListeners: function () {
372100% var me = this;
382100% me.container = $('.alertContainer');
392100% me.message = me.container.find('.message:first');
40 not covered
412100% $("#ok").on("click", me.hide.bind(me));
42 not covered }
43 not covered };
44 not covered
45 not covered // to pull into node namespace if included
461100%if (typeof module !== "undefined" && module.exports !== undefined) {
471100% module.exports = AlertController;
48 not covered }

lib/WutController.js

100% line coverage
100% statement coverage
100% block coverage
73 SLOC
LineHitsStatementsSourceAction
1 not covered /* globals jQuery, chrome, message, AlertController */
21100%"use strict";
3 not covered /**
4 not covered * Controller to handle the majority of the binding of events and actions for the user,
5 not covered * from clicking on various things to handling the copy to clipboard event and so forth.
6 not covered * @param {String} message the instance of AlertController class that this class needs
7 not covered */
81100%var WutController = function (message) {
91100% var me = this;
101100% me.message = message;
11 not covered };
12 not covered
131100%WutController.prototype = { /** * method to 0 pad a number between 0-9 (for the purpose of date/time) * @param {Number} n the number to pad * @return {Number} the padded number */ pad: function(n){
14 not covered /**
15 not covered * method to 0 pad a number between 0-9 (for the purpose of date/time)
16 not covered * @param {Number} n the number to pad
17 not covered * @return {Number} the padded number
18 not covered */
19 not covered pad: function(n){
2012100% return n < 10 ? '0' + n : n;
21 not covered },
22 not covered
23 not covered /**
24 not covered * focuses on the select input and selects it
25 not covered * @return {Collection} collection containing just the link item
26 not covered */
27 not covered selectAll: function(){
281100% var $link = $("#link");
291100% $link.focus();
301100% $link.select();
311100% return $link;
32 not covered },
33 not covered
34 not covered /**
35 not covered * execute the copy to clipboard operation
36 not covered * @return {Collection} collection containing just the link item
37 not covered */
38 not covered executeCopy: function(){
391100% var me = this,
401100% input = document.createElement('textarea'),
411100% $link = $("#link");
421100% document.body.appendChild(input);
431100% input.value = $link.html();
441100% input.focus();
451100% input.select();
461100% document.execCommand('Copy');
471100% input.remove();
481100% $(".linkHolder").addClass("copied");
491100% setTimeout(function() {
501100% $(".linkHolder").removeClass("copied");
51 not covered },2000);
521100% return $link;
53 not covered },
54 not covered
55 not covered /**
56 not covered * perform the ajax request to generate the link and delegate response callbacks
57 not covered * @return {Deferred} the deferred object generated by $.ajax
58 not covered */
59 not covered generateLink : function() {
604100% var me = this,
614100% url = $("#urlField").val() || $("#urlField").attr("placeholder"),
624100% activateDate = $("#activationDateField").val(),
634100% deactivateDate = $("#deactivationDateField").val(),
644100% button = $("#generateLink");
65 not covered
664100% if (button.hasClass("disabled")) {
671100% return false;
68 not covered }
69 not covered
703100% button.addClass("disabled").html("Generating...");
71 not covered
723100% return $.ajax({ url:"http://wut.link/", type:"POST", dataType: "json", data:{ url:url, activateDate: activateDate, deactivateDate: deactivateDate },
73 not covered url:"http://wut.link/",
74 not covered type:"POST",
75 not covered dataType: "json",
76 not covered data:{
77 not covered url:url,
78 not covered activateDate: activateDate,
79 not covered deactivateDate: deactivateDate
80 not covered },
813100% success: me.handleResponse.bind(me)
82 not covered });
83 not covered
84 not covered },
85 not covered
86 not covered /**
87 not covered * handle the actual ajax response (route to success or error callback)
88 not covered * @param {Object} response Response object
89 not covered * @return {Object} response Response object for potential chaining
90 not covered */
91 not covered handleResponse: function(response) {
922100% var me = this;
93 not covered if (response.errors) {
941100% me.onGenerateLinkError(response.errors);
95 not covered } else {
961100% me.onGenerateLinkSuccess(response);
97 not covered }
98 not covered
992100% me.resetGenerateLinkButton();
1002100% return response;
101 not covered },
102 not covered
103 not covered /**
104 not covered * generate error message returned trying to make link
105 not covered * @param {Object} errors object containing the errors
106 not covered * @return {Array} array of error Strings
107 not covered */
108 not covered onGenerateLinkError: function (errors) {
1091100% var me = this, text = [], error;
110 not covered text = [],
111 not covered error;
112 not covered
1131100% if (typeof errors === "object") {
114 not covered for (error in errors) {
1152100% if (errors.hasOwnProperty(error)) {
1162100% text = text.concat(errors[error]);
117 not covered }
118 not covered }
119 not covered }
120 not covered
1211100% if (text.length && me.message !== undefined) {
1221100% text.unshift("A link wasn't created because:<br>");
1231100% me.message.show(text.join('<br>'));
124 not covered }
125 not covered
1261100% return text;
127 not covered },
128 not covered
129 not covered /**
130 not covered * clear out the form after a successful link generation, and if copyAsap
131 not covered * is checked, also copy that link to the clipboard
132 not covered * @param {Object} response json response from server
133 not covered * @return {Object} json response from server
134 not covered */
135 not covered onGenerateLinkSuccess: function (response) {
1363100% var me = this, button = $("#generateLink");
137 not covered button = $("#generateLink");
1383100% $("#link").html(response.proxyUrl);
1393100% $(".linkHolder").addClass("loaded");
1403100% button.removeClass("disabled").html("Create Link");
1413100% if ($('#copyAsap').is(':checked')) {
1421100% me.executeCopy();
143 not covered }
144 not covered
1453100% return me;
146 not covered },
147 not covered
148 not covered /**
149 not covered * on chrome tab query, set the urlField's placeholder to the url
150 not covered * @param {Collection} tabs collection of chrome tabs
151 not covered * @return {Collection} collection of chrome tabs
152 not covered */
153 not covered onTabQuery: function(tabs) {
1541100% $("#urlField").attr("placeholder",tabs[0].url);
1551100% return tabs;
156 not covered },
157 not covered
158 not covered /**
159 not covered * entry point into the controller, binds event listeners and then
160 not covered * binds the event listeners on the child AlertController class.
161 not covered * @return {WutController} the instance for chaining
162 not covered */
163 not covered bindListeners: function() {
1641100% var me = this;
165 not covered // set placeholder to current url (will use this if not provided by user)
1661100% chrome.tabs.query({'active': true,'currentWindow':true}, me.onTabQuery);
167 not covered
1681100% $("#generateLink").on("click", me.generateLink.bind(me));
1691100% $("#link").on("click",this.selectAll);
1701100% $("#copyButton").on("click",this.executeCopy);
1711100% me.message.bindListeners();
172 not covered
1731100% return me;
174 not covered },
175 not covered
176 not covered /**
177 not covered * after an ajax attempt, clear the generate link styles and text
178 not covered * @return {Collection} collection of jQuery objects containing the button
179 not covered */
180 not covered resetGenerateLinkButton: function () {
1813100% $("#generateLink").removeClass("disabled");
1823100% $("#generateLink").html("Create Link");
1833100% return $("#generateLink");
184 not covered }
185 not covered };
186 not covered
187 not covered // to pull into node namespace if included
1881100%if (typeof module !== "undefined" && module.exports !== undefined) {
1891100% module.exports = WutController;
190 not covered }