blob: 17e00c9e696f58fd75b43cbd992f30f5916ea243 [file] [log] [blame]
Rushabh Mehtae67d1fb2013-08-05 14:59:54 +05301// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
2// License: GNU General Public License v3. See license.txt
3
Rushabh Mehta12852e72012-02-29 15:11:06 +05304wn.pages['activity'].onload = function(wrapper) {
Rushabh Mehtab394a252013-05-23 16:03:49 +05305 wn.ui.make_app_page({
6 parent: wrapper,
7 title: "Activity",
8 single_column: true
9 })
10 wrapper.appframe.add_module_icon("Activity");
Anand Doshiaea82042012-10-15 15:30:56 +053011
Rushabh Mehtaf81a64e2012-03-07 18:19:41 +053012 var list = new wn.ui.Listing({
Rushabh Mehta2146fd12012-04-17 12:40:37 +053013 appframe: wrapper.appframe,
Rushabh Mehta12852e72012-02-29 15:11:06 +053014 method: 'home.page.activity.activity.get_feed',
Rushabh Mehtab394a252013-05-23 16:03:49 +053015 parent: $(wrapper).find(".layout-main"),
Rushabh Mehta12852e72012-02-29 15:11:06 +053016 render_row: function(row, data) {
17 new erpnext.ActivityFeed(row, data);
18 }
19 });
20 list.run();
Anand Doshiaea82042012-10-15 15:30:56 +053021
22 // Build Report Button
23 if(wn.boot.profile.can_get_report.indexOf("Feed")!=-1) {
24 wrapper.appframe.add_button('Build Report', function() {
Rushabh Mehta8fefeaf2013-06-04 11:23:42 +053025 wn.set_route('Report', "Feed");
Anand Doshiaea82042012-10-15 15:30:56 +053026 }, 'icon-th')
27 }
Rushabh Mehta12852e72012-02-29 15:11:06 +053028}
29
30erpnext.last_feed_date = false;
31erpnext.ActivityFeed = Class.extend({
32 init: function(row, data) {
33 this.scrub_data(data);
34 this.add_date_separator(row, data);
Rushabh Mehta0db74a72012-12-07 15:47:32 +053035 $(row).append(repl('<div style="margin: 0px">\
Rushabh Mehtab62bbc62012-10-03 18:32:10 +053036 <span class="avatar avatar-small"><img src="%(imgsrc)s" /></span> \
Rushabh Mehtab4a2f4c2012-03-01 11:49:54 +053037 <span %(onclick)s class="label %(add_class)s">%(feed_type)s</span>\
38 %(link)s %(subject)s <span class="user-info">%(by)s</span></div>', data));
Rushabh Mehta12852e72012-02-29 15:11:06 +053039 },
40 scrub_data: function(data) {
Rushabh Mehta204e77d2012-02-29 19:09:20 +053041 data.by = wn.user_info(data.owner).fullname;
Rushabh Mehta24a69612012-12-11 15:58:19 +053042 data.imgsrc = wn.utils.get_file_link(wn.user_info(data.owner).image);
Rushabh Mehta12852e72012-02-29 15:11:06 +053043
44 // feedtype
45 if(!data.feed_type) {
Rushabh Mehta291449b2012-12-13 12:53:21 +053046 data.feed_type = wn._(data.doc_type);
Rushabh Mehta12852e72012-02-29 15:11:06 +053047 data.add_class = "label-info";
48 data.onclick = repl('onclick="window.location.href=\'#!List/%(feed_type)s\';"', data)
49 }
50
51 // color for comment
52 if(data.feed_type=='Comment') {
53 data.add_class = "label-important";
54 }
55
Rushabh Mehta79ae1652012-02-29 15:23:25 +053056 if(data.feed_type=='Assignment') {
Rushabh Mehta1572adf2012-02-29 15:19:20 +053057 data.add_class = "label-warning";
58 }
59
Rushabh Mehta12852e72012-02-29 15:11:06 +053060 // link
61 if(data.doc_name && data.feed_type!='Login') {
Rushabh Mehta8956c672013-07-05 16:23:19 +053062 data.link = wn.format(data.doc_name, {"fieldtype":"Link", "options":data.doc_type})
Rushabh Mehta0db74a72012-12-07 15:47:32 +053063 } else {
64 data.link = "";
Rushabh Mehta12852e72012-02-29 15:11:06 +053065 }
66 },
67 add_date_separator: function(row, data) {
68 var date = dateutil.str_to_obj(data.modified);
69 var last = erpnext.last_feed_date;
70
Rushabh Mehtae45ffd62012-03-02 16:25:22 +053071 if((last && dateutil.obj_to_str(last) != dateutil.obj_to_str(date)) || (!last)) {
72 var diff = dateutil.get_day_diff(new Date(), date);
Rushabh Mehta12852e72012-02-29 15:11:06 +053073 if(diff < 1) {
74 pdate = 'Today';
Rushabh Mehtae45ffd62012-03-02 16:25:22 +053075 } else if(diff < 2) {
76 pdate = 'Yesterday';
77 } else {
Rushabh Mehta12852e72012-02-29 15:11:06 +053078 pdate = dateutil.global_date_format(date);
79 }
80 $(row).html(repl('<div class="date-sep">%(date)s</div>', {date: pdate}));
81 }
82 erpnext.last_feed_date = date;
83 }
84})