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

65 lines
2.0 KiB
JavaScript
Raw Normal View History

2012-02-29 09:41:06 +00:00
wn.pages['activity'].onload = function(wrapper) {
var list = new wn.widgets.Listing({
method: 'home.page.activity.activity.get_feed',
parent: $('#activity-list'),
render_row: function(row, data) {
new erpnext.ActivityFeed(row, data);
}
});
list.run();
}
erpnext.last_feed_date = false;
erpnext.ActivityFeed = Class.extend({
init: function(row, data) {
this.scrub_data(data);
this.add_date_separator(row, data);
2012-03-01 06:19:54 +00:00
$(row).append(sprintf('<div style="margin: 0px">\
2012-03-01 08:00:34 +00:00
<span style="display: inline-block; min-width: 29px;">
2012-03-01 06:49:18 +00:00
<img src="%(imgsrc)s" style= "height: 24px; margin-bottom: -7px; \
2012-03-01 08:00:34 +00:00
max-width: 24px;"></span> \
2012-03-01 06:19:54 +00:00
<span %(onclick)s class="label %(add_class)s">%(feed_type)s</span>\
%(link)s %(subject)s <span class="user-info">%(by)s</span></div>', data));
2012-02-29 09:41:06 +00:00
},
scrub_data: function(data) {
2012-02-29 13:39:20 +00:00
data.by = wn.user_info(data.owner).fullname;
2012-03-01 06:19:54 +00:00
data.imgsrc = wn.user_info(data.owner).image;
2012-02-29 09:41:06 +00:00
// feedtype
if(!data.feed_type) {
data.feed_type = get_doctype_label(data.doc_type);
data.add_class = "label-info";
data.onclick = repl('onclick="window.location.href=\'#!List/%(feed_type)s\';"', data)
}
// color for comment
if(data.feed_type=='Comment') {
data.add_class = "label-important";
}
2012-02-29 09:53:25 +00:00
if(data.feed_type=='Assignment') {
2012-02-29 09:49:20 +00:00
data.add_class = "label-warning";
}
2012-02-29 09:41:06 +00:00
// link
if(data.doc_name && data.feed_type!='Login') {
data.link = repl('<a href="#!Form/%(doc_type)s/%(doc_name)s">%(doc_name)s</a>', data)
}
},
add_date_separator: function(row, data) {
var date = dateutil.str_to_obj(data.modified);
var last = erpnext.last_feed_date;
if((last && dateutil.get_diff(last, date)>1) || (!last)) {
var pdate = dateutil.comment_when(date);
var diff = dateutil.get_diff(new Date(), date);
if(diff < 1) {
pdate = 'Today';
} else if(diff > 6) {
pdate = dateutil.global_date_format(date);
}
$(row).html(repl('<div class="date-sep">%(date)s</div>', {date: pdate}));
}
erpnext.last_feed_date = date;
}
})