brotherton-erpnext/utilities/page/todo/todo.js

201 lines
5.6 KiB
JavaScript
Raw Normal View History

2012-02-28 12:10:13 +00:00
// ERPNext - web based ERP (http://erpnext.com)
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
2012-02-24 05:56:31 +00:00
wn.provide('erpnext.todo');
erpnext.todo.refresh = function() {
wn.call({
method: 'utilities.page.todo.todo.get',
callback: function(r,rt) {
var todo_list = $('#todo-list div.todo-content');
var assigned_todo_list = $('#assigned-todo-list div.todo-content');
todo_list.empty();
assigned_todo_list.empty();
var nothing_to_do = function() {
$('#todo-list div.todo-content')
.html('<div class="alert">Nothing to do :)</div>');
}
2012-02-24 05:56:31 +00:00
if(r.message) {
for(var i in r.message) {
new erpnext.todo.ToDoItem(r.message[i]);
}
if (!todo_list.html()) { nothing_to_do(); }
2012-02-24 05:56:31 +00:00
} else {
nothing_to_do();
2012-02-24 05:56:31 +00:00
}
}
});
}
erpnext.todo.ToDoItem = Class.extend({
init: function(todo) {
label_map = {
'High': 'label-important',
'Medium': 'label-info',
'Low':''
}
todo.labelclass = label_map[todo.priority];
2012-03-21 12:32:17 +00:00
todo.userdate = dateutil.str_to_user(todo.date) || '';
2012-06-12 13:54:12 +00:00
todo.fullname = '';
2012-03-22 05:31:38 +00:00
if(todo.assigned_by) {
2012-06-14 11:16:48 +00:00
var assigned_by = wn.boot.user_info[todo.assigned_by]
todo.fullname = repl("[By %(fullname)s] ".bold(), {
2012-06-14 11:16:48 +00:00
fullname: (assigned_by ? assigned_by.fullname : todo.assigned_by),
2012-06-12 13:54:12 +00:00
});
}
var parent_list = "#todo-list";
if(todo.owner !== user) {
2012-06-14 11:16:48 +00:00
var owner = wn.boot.user_info[todo.owner];
todo.fullname = repl("[To %(fullname)s] ".bold(), {
2012-06-14 11:16:48 +00:00
fullname: (owner ? owner.fullname : todo.owner),
2012-06-12 13:54:12 +00:00
});
}
parent_list += " div.todo-content";
2012-02-29 13:03:39 +00:00
if(todo.reference_name && todo.reference_type) {
todo.link = repl('<a href="#!Form/%(reference_type)s/%(reference_name)s">\
2012-03-21 12:32:17 +00:00
%(reference_type)s: %(reference_name)s</a>', todo);
2012-02-29 13:03:39 +00:00
} else if(todo.reference_type) {
2012-08-08 10:00:19 +00:00
todo.link = repl('<br><a href="#!List/%(reference_type)s">\
2012-02-29 13:03:39 +00:00
%(reference_type)s</a>', todo);
} else {
todo.link = '';
}
2012-04-03 06:48:35 +00:00
if(!todo.description) todo.description = '';
2012-06-12 13:54:12 +00:00
$(parent_list).append(repl('\
<div class="todoitem">\
<span class="label %(labelclass)s">%(priority)s</span>\
<span class="popup-on-click"><a href="#">[edit]</a></span>\
2012-02-24 05:56:31 +00:00
<span class="description">\
<span class="help" style="margin-right: 7px">%(userdate)s</span>\
%(fullname)s: %(description)s\
2012-08-08 10:00:19 +00:00
<span class="ref_link">%(link)s</span>\
2012-06-12 13:54:12 +00:00
</span>\
<span class="close-span"><a href="#" class="close">&times;</a></span>\
</div>\
<div class="todo-separator"></div>', todo));
$todo = $(parent_list + ' div.todoitem:last');
2012-02-24 05:56:31 +00:00
if(todo.checked) {
$todo.find('.description').css('text-decoration', 'line-through');
}
2012-02-29 13:03:39 +00:00
if(!todo.reference_type)
2012-02-24 05:56:31 +00:00
$todo.find('.ref_link').toggle(false);
2012-06-13 11:31:52 +00:00
$todo.find('.popup-on-click')
2012-02-24 05:56:31 +00:00
.data('todo', todo)
.click(function() {
erpnext.todo.make_dialog($(this).data('todo'));
return false;
});
$todo.find('.close')
.data('name', todo.name)
.click(function() {
$(this).parent().css('opacity', 0.5);
wn.call({
method:'utilities.page.todo.todo.delete',
args: {name: $(this).data('name')},
callback: function() {
erpnext.todo.refresh();
}
});
return false;
})
}
});
erpnext.todo.make_dialog = function(det) {
if(!erpnext.todo.dialog) {
var dialog = new wn.ui.Dialog({
2012-02-24 05:56:31 +00:00
width: 480,
title: 'To Do',
fields: [
2012-08-07 07:23:49 +00:00
{fieldtype:'Text', fieldname:'description', label:'Description',
reqd:1},
2012-08-07 11:06:10 +00:00
{fieldtype:'Date', fieldname:'date', label:'Event Date', reqd:1},
2012-02-24 05:56:31 +00:00
{fieldtype:'Check', fieldname:'checked', label:'Completed'},
{fieldtype:'Select', fieldname:'priority', label:'Priority', reqd:1, 'options':['Medium','High','Low'].join('\n')},
{fieldtype:'Button', fieldname:'save', label:'Save (Ctrl+S)'}
2012-02-24 05:56:31 +00:00
]
});
dialog.fields_dict.save.input.onclick = function() {
erpnext.todo.save(this);
}
erpnext.todo.dialog = dialog;
}
if(det) {
erpnext.todo.dialog.set_values({
date: det.date,
priority: det.priority,
description: det.description,
checked: det.checked
});
erpnext.todo.dialog.det = det;
}
erpnext.todo.dialog.show();
}
erpnext.todo.save = function(btn) {
var d = erpnext.todo.dialog;
var det = d.get_values();
if(!det) {
return;
}
det.name = d.det.name || '';
wn.call({
method:'utilities.page.todo.todo.edit',
args: det,
btn: btn,
callback: function() {
erpnext.todo.dialog.hide();
erpnext.todo.refresh();
}
});
}
2012-07-09 07:04:02 +00:00
wn.pages.todo.onload = function(wrapper) {
// create app frame
wrapper.appframe = new wn.ui.AppFrame($(wrapper).find('.appframe-area'), 'To Do');
wrapper.appframe.add_button('Refresh', erpnext.todo.refresh, 'icon-refresh');
wrapper.appframe.add_button('Add', function() {
erpnext.todo.make_dialog({
date:get_today(), priority:'Medium', checked:0, description:''});
}, 'icon-plus');
wrapper.appframe.add_ripped_paper_effect(wrapper);
2012-07-09 07:04:02 +00:00
2012-02-24 05:56:31 +00:00
// load todos
erpnext.todo.refresh();
// save on click
wrapper.save_action = function() {
if(erpnext.todo.dialog && erpnext.todo.dialog.display) {
erpnext.todo.dialog.fields_dict.save.input.click();
}
};
2012-06-14 11:16:48 +00:00
}