Commit c0c918ec authored by Leo Iannacone's avatar Leo Iannacone

jslint client code

parent 08e14f2f
"use strict";
/* /*
General information about debugging: General information about debugging:
...@@ -10,17 +11,17 @@ ...@@ -10,17 +11,17 @@
3 - socket emit data 3 - socket emit data
4 - socket received data 4 - socket received data
*/ */
var debug = function() { var debug = function () {
if (arguments.length < 2) { if (arguments.length < 2) {
return return;
} }
var level = arguments[0] var level = arguments[0];
arguments[0] = "debug [" + level + "]:" arguments[0] = "debug [" + level + "]:";
if (level <= config.preferences.debug) { if (level <= config.preferences.debug) {
if (console.debug) if (console.debug)
console.debug.apply(console, arguments) console.debug.apply(console, arguments);
else else
console.log.apply(console, arguments) console.log.apply(console, arguments);
} }
} }
...@@ -30,11 +31,11 @@ var debug = function() { ...@@ -30,11 +31,11 @@ var debug = function() {
usage: debug_socket("emit"|"received", event_name, data) usage: debug_socket("emit"|"received", event_name, data)
*/ */
var debug_socket = function() { var debug_socket = function () {
if (arguments.length != 3) if (arguments.length != 3)
return return;
var level = 3; var level = 3;
if (arguments[0] == "received") if (arguments[0] == "received")
level = 4 level = 4;
debug(level, "socket", arguments[0], "event:", arguments[1], "data:", arguments[2]) debug(level, "socket", arguments[0], "event:", arguments[1], "data:", arguments[2]);
} }
// main client javascript // main client javascript
'use strict';
var preferences = new Preferences() var preferences = new Preferences();
var page_generic = new Page_Generic() var page_generic = new Page_Generic();
if (window.location.pathname == config.paths.preferences) { if (window.location.pathname == config.paths.preferences) {
preferences.initPage() preferences.initPage();
} }
if (window.location.pathname == '/') { if (window.location.pathname == '/') {
// convert email addresses in the right format // convert email addresses in the right format
var emails = $(".email") var emails = $('.email');
$.each(emails, function (){ $.each(emails, function () {
var subject = '' var subject = '';
if ($(this).attr('subject')) { if ($(this).attr('subject')) {
subject = '?subject=' + $(this).attr('subject') subject = '?subject=' + $(this).attr('subject');
} }
var real_email = $(this).attr('address').replace('AT','@').replace('DOT','.').replace(/ /g,'') var real_email = $(this).attr('address').replace('AT', '@').replace('DOT', '.').replace(/ /g, '');
var label = real_email var label = real_email;
if (config.debomatic.admin.name && config.debomatic.admin.name != 'Your Name') if (config.debomatic.admin.name && config.debomatic.admin.name != 'Your Name');
label = config.debomatic.admin.name label = config.debomatic.admin.name;
real_email = '<a href="mailto:' + real_email + subject + '">' + label + '</a>' real_email = '<a href="mailto:' + real_email + subject + '">' + label + '</a>';
$(this).html(real_email) $(this).html(real_email);
}) })
} }
var socket = io.connect('/'); var socket = io.connect('/');
page_generic.start(socket) page_generic.start(socket);
if (window.location.pathname == config.paths.distribution) { if (window.location.pathname == config.paths.distribution) {
new Page_Distrubion(socket).start() new Page_Distrubion(socket).start();
} }
'use strict';
function Preferences() { function Preferences() {
// update config.preferences according with user choices // update config.preferences according with user choices
var load = function () { var load = function () {
for (key in config.preferences) { for (var key in config.preferences) {
if ((value = localStorage.getItem(key))) { var value = localStorage.getItem(key);
debug(2, 'loading preference', key, value) if (value) {
config.preferences[key] = JSON.parse(value) debug(2, 'loading preference', key, value);
} config.preferences[key] = JSON.parse(value);
} }
} }
};
// set prefence // set prefence
var set = function (key, value) { var set = function (key, value) {
if (config.preferences.hasOwnProperty(key)) { if (config.preferences.hasOwnProperty(key)) {
debug(1, 'setting preference', key, value) debug(1, 'setting preference', key, value);
localStorage.setItem(key, value) localStorage.setItem(key, value);
config.preferences[key] = JSON.parse(value) config.preferences[key] = JSON.parse(value);
}
} }
};
// init prefence page // init prefence page
this.initPage = function() { this.initPage = function () {
page_generic.set_window_title("Preferences") page_generic.set_window_title('Preferences');
// set view according with config.preferences // set view according with config.preferences
for (key in config.preferences) { for (var key in config.preferences) {
var element = $("#preferences #" + key) var element = $('#preferences #' + key);
if (element.attr('type') == "checkbox") { if (element.attr('type') == 'checkbox') {
element.prop('checked', config.preferences[key]) element.prop('checked', config.preferences[key]);
} } else {
else { element.val(config.preferences[key]);
element.val(config.preferences[key])
} }
} }
// on input change, set prefence // on input change, set prefence
$("#preferences input, #preferences select").change(function() { $('#preferences input, #preferences select').change(function () {
var key = $(this).attr('id') var key = $(this).attr('id');
var value = $(this).val() var value = $(this).val();
if ($(this).attr('type') == 'checkbox') if ($(this).attr('type') == 'checkbox')
value = $(this).is(':checked') value = $(this).is(':checked');
set(key,value) set(key, value);
// give to user an immediate feedback changing preferences // give to user an immediate feedback changing preferences
page_generic.preferences() page_generic.preferences();
}) });
} };
load() load();
} }
'use strict';
var Utils = { var Utils = {
from_hash_to_view: function (hash) { from_hash_to_view: function (hash) {
if (! hash ) if (!hash)
hash = window.location.hash hash = window.location.hash;
hash = hash.replace('#', '') hash = hash.replace('#', '');
info = hash.split('/'); var info = hash.split('/');
var view = {} var view = {};
view.distribution = {} view.distribution = {};
view.packages = {} view.packages = {};
view.package = {} view.package = {};
view.file = {} view.file = {};
if (info.length >= 1) { if (info.length >= 1) {
view.distribution.name = info[0]; view.distribution.name = info[0];
} }
if (info.length >= 3){ if (info.length >= 3) {
view.package.name = info[1]; view.package.name = info[1];
view.package.version = info[2]; view.package.version = info[2];
view.package.orig_name = view.package.name + '_' + view.package.version view.package.orig_name = view.package.name + '_' + view.package.version;
} }
if (info.length >= 4) { if (info.length >= 4) {
view.file.name = info[3] view.file.name = info[3];
view.file.orig_name = view.package.orig_name + '.' + view.file.name view.file.orig_name = view.package.orig_name + '.' + view.file.name;
} }
return view return view;
}, },
from_view_to_hash: function (view) { from_view_to_hash: function (view) {
hash = "#" var hash = '#';
if (Utils.check_view_distribution(view)) { if (Utils.check_view_distribution(view)) {
hash = hash + view.distribution.name hash = hash + view.distribution.name;
if (Utils.check_view_package(view)) { if (Utils.check_view_package(view)) {
hash = hash + '/' + view.package.name + "/" + view.package.version hash = hash + '/' + view.package.name + '/' + view.package.version;
if (Utils.check_view_file(view)) if (Utils.check_view_file(view))
hash = hash + '/' + view.file.name hash = hash + '/' + view.file.name;
} }
} }
return hash return hash;
}, },
check_view_distribution: function(view) { check_view_distribution: function (view) {
return view && view.distribution && view.distribution.name return view && view.distribution && view.distribution.name;
}, },
check_view_package: function(view) { check_view_package: function (view) {
return Utils.check_view_distribution(view) && view.package && view.package.name && view.package.version && view.package.orig_name return Utils.check_view_distribution(view) && view.package && view.package.name && view.package.version && view.package.orig_name;
}, },
check_view_file: function(view) { check_view_file: function (view) {
return Utils.check_view_package(view) && view.file && view.file.name return Utils.check_view_package(view) && view.file && view.file.name;
}, },
get_status_icon_and_class: function (status_data) { get_status_icon_and_class: function (status_data) {
var _c = config.status.className var _c = config.status.className;
var _i = config.status.icons var _i = config.status.icons;
var _s = status_data var _s = status_data;
var className = null var className = null;
var icon = null var icon = null;
if (_s.hasOwnProperty('success')) { if (_s.hasOwnProperty('success')) {
if (_s.success == true) { if (_s.success === true) {
className = _c.success className = _c.success;
icon = _i.success icon = _i.success;
} } else {
else { className = _c.fail;
className = _c.fail icon = _i.fail;
icon = _i.fail
} }
} } else {
else { className = _c[_s.status];
className = _c[_s.status] icon = _i[_s.status];
icon = _i[_s.status]
} }
// do not change color if update or create and successed // do not change color if update or create and successed
if (_s.success == true && if (_s.success === true &&
_s.status != config.status.build) _s.status != config.status.build) {
{ className = _c[_s.status];
className = _c[_s.status]
} }
return { return {
className: className, className: className,
icon: icon icon: icon
} };
}, },
get_status_icon_html: function (status_data) { get_status_icon_html: function (status_data) {
info = Utils.get_status_icon_and_class(status_data) var info = Utils.get_status_icon_and_class(status_data);
return '<span class="icon glyphicon glyphicon-' + info.icon + '"></span>' return '<span class="icon glyphicon glyphicon-' + info.icon + '"></span>';
}, },
// clone an object via JSON // clone an object via JSON
clone: function (object) { clone: function (object) {
return JSON.parse(JSON.stringify(object)); return JSON.parse(JSON.stringify(object));
} }
} };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment