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

81 lines
2.3 KiB
JavaScript
Raw Normal View History

2012-02-29 09:41:06 +00:00
wn.pages['activity'].onload = function(wrapper) {
wn.ui.make_app_page({
parent: wrapper,
title: "Activity",
single_column: true
})
wrapper.appframe.add_module_icon("Activity");
2012-10-15 10:00:56 +00:00
var list = new wn.ui.Listing({
2012-04-17 07:10:37 +00:00
appframe: wrapper.appframe,
2012-02-29 09:41:06 +00:00
method: 'home.page.activity.activity.get_feed',
parent: $(wrapper).find(".layout-main"),
2012-02-29 09:41:06 +00:00
render_row: function(row, data) {
new erpnext.ActivityFeed(row, data);
}
});
list.run();
2012-10-15 10:00:56 +00:00
// Build Report Button
if(wn.boot.profile.can_get_report.indexOf("Feed")!=-1) {
wrapper.appframe.add_button('Build Report', function() {
wn.set_route('Report', "Feed");
2012-10-15 10:00:56 +00:00
}, 'icon-th')
}
2012-02-29 09:41:06 +00:00
}
erpnext.last_feed_date = false;
erpnext.ActivityFeed = Class.extend({
init: function(row, data) {
this.scrub_data(data);
this.add_date_separator(row, data);
$(row).append(repl('<div style="margin: 0px">\
2012-10-03 13:02:10 +00:00
<span class="avatar avatar-small"><img src="%(imgsrc)s" /></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-12-11 10:28:19 +00:00
data.imgsrc = wn.utils.get_file_link(wn.user_info(data.owner).image);
2012-02-29 09:41:06 +00:00
// feedtype
if(!data.feed_type) {
2012-12-13 07:23:21 +00:00
data.feed_type = wn._(data.doc_type);
2012-02-29 09:41:06 +00:00
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 = wn.format(data.doc_name, {"fieldtype":"Link", "options":data.doc_type})
} else {
data.link = "";
2012-02-29 09:41:06 +00:00
}
},
add_date_separator: function(row, data) {
var date = dateutil.str_to_obj(data.modified);
var last = erpnext.last_feed_date;
2012-03-02 10:55:22 +00:00
if((last && dateutil.obj_to_str(last) != dateutil.obj_to_str(date)) || (!last)) {
var diff = dateutil.get_day_diff(new Date(), date);
2012-02-29 09:41:06 +00:00
if(diff < 1) {
pdate = 'Today';
2012-03-02 10:55:22 +00:00
} else if(diff < 2) {
pdate = 'Yesterday';
} else {
2012-02-29 09:41:06 +00:00
pdate = dateutil.global_date_format(date);
}
$(row).html(repl('<div class="date-sep">%(date)s</div>', {date: pdate}));
}
erpnext.last_feed_date = date;
}
})