brotherton-erpnext/home/page/desktop/desktop.js
2012-12-22 07:42:04 +05:30

93 lines
2.8 KiB
JavaScript

wn.provide('erpnext.desktop');
erpnext.desktop.refresh = function() {
erpnext.desktop.render();
$("#icon-grid").sortable({
update: function() {
new_order = [];
$("#icon-grid .case-wrapper").each(function(i, e) {
new_order.push($(this).attr("data-name"));
});
wn.user.set_default("_desktop_items", new_order);
}
});
}
erpnext.desktop.render = function() {
var add_icon = function(m) {
var module = wn.modules[m];
if(!module.label)
module.label = m;
module.name = m;
module.gradient_css = wn.get_gradient_css(module.color, 45);
$('#icon-grid').append(repl('\
<div id="module-icon-%(link)s" class="case-wrapper" data-name="%(name)s"><a href="#%(link)s">\
<div class="case-border" style="%(gradient_css)s">\
<i class="%(icon)s"></i>\
</div></a>\
<div class="case-label">%(label)s</div>\
</div>', module));
}
// modules
var modules_list = wn.user.get_desktop_items();
$.each(modules_list, function(i, m) {
if(!in_list(['Setup', 'Core'], m) && wn.boot.profile.allow_modules.indexOf(m)!=-1)
add_icon(m);
})
// setup
if(user_roles.indexOf('System Manager')!=-1)
add_icon('Setup')
// notifications
erpnext.desktop.show_pending_notifications();
}
erpnext.desktop.show_pending_notifications = function() {
var add_circle = function(str_module, id, title) {
var module = $('#'+str_module);
module.find('a:first').append(
repl('<div id="%(id)s" class="circle" title="%(title)s" style="display: None">\
<span class="circle-text"></span>\
</div>', {id: id, title: title}));
var case_border = module.find('.case-border');
var circle = module.find('.circle');
var add_hover_and_click = function(primary, secondary, hover_class, click_class) {
primary
.hover(
function() { secondary.addClass(hover_class); },
function() { secondary.removeClass(hover_class); })
.mousedown(function() { secondary.addClass(click_class); })
.mouseup(function() { secondary.removeClass(click_class); })
.focusin(function() { $(this).mousedown(); })
.focusout(function() { $(this).mouseup(); })
}
add_hover_and_click(case_border, circle, 'hover-effect', 'circle-click');
add_hover_and_click(circle, case_border, 'hover-effect', 'case-border-click');
}
add_circle('module-icon-messages', 'unread_messages', 'Unread Messages');
add_circle('module-icon-support-home', 'open_support_tickets', 'Open Support Tickets');
add_circle('module-icon-todo', 'things_todo', 'Things To Do');
add_circle('module-icon-calendar', 'todays_events', 'Todays Events');
add_circle('module-icon-projects-home', 'open_tasks', 'Open Tasks');
add_circle('module-icon-questions', 'unanswered_questions', 'Unanswered Questions');
erpnext.update_messages();
}
pscript.onload_desktop = function() {
// load desktop
erpnext.desktop.refresh();
}