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

79 lines
2.4 KiB
JavaScript
Raw Normal View History

2012-02-29 09:41:06 +00:00
wn.pages['activity'].onload = function(wrapper) {
2012-04-17 07:10:37 +00:00
wrapper.appframe = new wn.ui.AppFrame($(wrapper).find('.layout-appframe'));
wrapper.appframe.add_home_breadcrumb();
wrapper.appframe.add_breadcrumb(wn.modules["Activity"].icon);
2012-04-17 07:10:37 +00:00
wrapper.appframe.title('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: $('#activity-list'),
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('Report2', "Feed");
}, '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 = repl('<a href="#!Form/%(doc_type)s/%(doc_name)s">%(doc_name)s</a>', data)
} 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;
}
})