Commit c0c918ec authored by Leo Iannacone's avatar Leo Iannacone

jslint client code

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