brotherton-erpnext/home/page/desktop/desktop.js

95 lines
2.8 KiB
JavaScript
Raw Normal View History

2012-02-24 09:59:07 +00:00
wn.provide('erpnext.desktop');
erpnext.desktop.refresh = function() {
erpnext.desktop.render();
2012-12-21 09:30:29 +00:00
$("#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);
}
2012-02-24 09:59:07 +00:00
});
}
erpnext.desktop.render = function() {
2012-12-28 05:00:46 +00:00
document.title = "Desktop";
2012-02-29 05:25:43 +00:00
var add_icon = function(m) {
2012-12-21 09:30:29 +00:00
var module = wn.modules[m];
if(!module.label)
module.label = m;
module.name = m;
2013-01-07 10:09:54 +00:00
module.label = wn._(module.label);
2012-12-21 09:30:29 +00:00
module.gradient_css = wn.get_gradient_css(module.color, 45);
2012-02-28 13:26:56 +00:00
$('#icon-grid').append(repl('\
2012-12-21 09:30:29 +00:00
<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>\
2012-02-24 09:59:07 +00:00
</div></a>\
<div class="case-label">%(label)s</div>\
2012-12-21 09:30:29 +00:00
</div>', module));
2012-02-28 13:26:56 +00:00
}
2012-12-21 09:30:29 +00:00
// modules
2012-12-22 02:12:04 +00:00
var modules_list = wn.user.get_desktop_items();
2012-12-21 09:30:29 +00:00
$.each(modules_list, function(i, m) {
2012-11-15 11:28:27 +00:00
if(!in_list(['Setup', 'Core'], m) && wn.boot.profile.allow_modules.indexOf(m)!=-1)
2012-02-29 05:25:43 +00:00
add_icon(m);
2012-12-21 09:30:29 +00:00
})
2012-03-01 05:54:45 +00:00
2012-12-21 09:30:29 +00:00
// setup
2012-02-28 13:26:56 +00:00
if(user_roles.indexOf('System Manager')!=-1)
2012-02-29 05:25:43 +00:00
add_icon('Setup')
2012-02-24 09:59:07 +00:00
2012-12-21 09:30:29 +00:00
// notifications
2012-02-24 12:26:00 +00:00
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>\
2013-01-07 10:09:54 +00:00
</div>', {id: id, title: wn._(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');
}
2012-12-21 09:30:29 +00:00
add_circle('module-icon-messages', 'unread_messages', 'Unread Messages');
2012-12-21 16:10:19 +00:00
add_circle('module-icon-support-home', 'open_support_tickets', 'Open Support Tickets');
2012-12-21 09:30:29 +00:00
add_circle('module-icon-todo', 'things_todo', 'Things To Do');
add_circle('module-icon-calendar', 'todays_events', 'Todays Events');
2012-12-21 17:19:10 +00:00
add_circle('module-icon-projects-home', 'open_tasks', 'Open Tasks');
2012-12-21 16:10:19 +00:00
add_circle('module-icon-questions', 'unanswered_questions', 'Unanswered Questions');
2012-05-03 05:14:44 +00:00
erpnext.update_messages();
2012-02-24 12:26:00 +00:00
2012-02-24 09:59:07 +00:00
}
pscript.onload_desktop = function() {
// load desktop
erpnext.desktop.refresh();
}