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

89 lines
2.7 KiB
JavaScript
Raw Normal View History

2013-11-20 07:29:58 +00:00
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt
2014-02-14 10:17:51 +00:00
frappe.pages['activity'].onload = function(wrapper) {
frappe.ui.make_app_page({
parent: wrapper,
2014-04-14 10:55:30 +00:00
title: __("Activity"),
single_column: true
})
wrapper.appframe.add_module_icon("Activity");
2014-08-07 09:54:26 +00:00
2014-02-14 10:17:51 +00:00
var list = new frappe.ui.Listing({
hide_refresh: true,
2012-04-17 07:10:37 +00:00
appframe: wrapper.appframe,
method: 'erpnext.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();
wrapper.appframe.set_title_right("Refresh", function() { list.run(); });
2014-08-07 09:54:26 +00:00
2012-10-15 10:00:56 +00:00
// Build Report Button
if(frappe.boot.user.can_get_report.indexOf("Feed")!=-1) {
2014-08-14 06:13:27 +00:00
wrapper.appframe.add_button(__('Build Report'), function() {
2014-02-14 10:17:51 +00:00
frappe.set_route('Report', "Feed");
2014-08-14 06:13:27 +00:00
}, 'icon-th');
2012-10-15 10:00:56 +00:00
}
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);
2013-09-04 12:56:51 +00:00
if(!data.add_class) data.add_class = "label-default";
$(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) {
2014-02-14 10:17:51 +00:00
data.by = frappe.user_info(data.owner).fullname;
data.imgsrc = frappe.utils.get_file_link(frappe.user_info(data.owner).image);
2014-08-07 09:54:26 +00:00
2012-02-29 09:41:06 +00:00
// feedtype
if(!data.feed_type) {
2014-04-14 10:55:30 +00:00
data.feed_type = __(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)
}
2014-08-07 09:54:26 +00:00
2012-02-29 09:41:06 +00:00
// color for comment
if(data.feed_type=='Comment') {
2013-09-04 12:56:51 +00:00
data.add_class = "label-danger";
2012-02-29 09:41:06 +00:00
}
2014-08-07 09:54:26 +00:00
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";
}
2014-08-07 09:54:26 +00:00
2012-02-29 09:41:06 +00:00
// link
if(data.doc_name && data.feed_type!='Login') {
2014-02-14 10:17:51 +00:00
data.link = frappe.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;
2014-08-07 09:54:26 +00:00
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(dateutil.get_today(), dateutil.obj_to_str(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);
}
2014-08-14 06:13:27 +00:00
$(row).html(repl('<div class="date-sep" style="padding-left: 15px;">%(date)s</div>', {date: pdate}));
2012-02-29 09:41:06 +00:00
}
erpnext.last_feed_date = date;
}
2014-08-07 09:54:26 +00:00
})