blob: ef7ccd9b0e154cedf24ef10616e028335ea814d9 [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,
Bárbara Perrettif6a63992013-10-07 14:06:23 -03007 title: wn._("Activity"),
Rushabh Mehtab394a252013-05-23 16:03:49 +05308 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 Mehta4f642e72013-11-13 16:55:38 +053013 hide_refresh: true,
Rushabh Mehta2146fd12012-04-17 12:40:37 +053014 appframe: wrapper.appframe,
Rushabh Mehta12852e72012-02-29 15:11:06 +053015 method: 'home.page.activity.activity.get_feed',
Rushabh Mehtab394a252013-05-23 16:03:49 +053016 parent: $(wrapper).find(".layout-main"),
Rushabh Mehta12852e72012-02-29 15:11:06 +053017 render_row: function(row, data) {
18 new erpnext.ActivityFeed(row, data);
19 }
20 });
21 list.run();
Rushabh Mehta4f642e72013-11-13 16:55:38 +053022
23 wrapper.appframe.set_title_right("Refresh", function() { list.run(); });
Anand Doshiaea82042012-10-15 15:30:56 +053024
25 // Build Report Button
26 if(wn.boot.profile.can_get_report.indexOf("Feed")!=-1) {
Rushabh Mehta4f642e72013-11-13 16:55:38 +053027 wrapper.appframe.add_primary_action(wn._('Build Report'), function() {
Rushabh Mehta8fefeaf2013-06-04 11:23:42 +053028 wn.set_route('Report', "Feed");
Anand Doshiaea82042012-10-15 15:30:56 +053029 }, 'icon-th')
30 }
Rushabh Mehta12852e72012-02-29 15:11:06 +053031}
32
33erpnext.last_feed_date = false;
34erpnext.ActivityFeed = Class.extend({
35 init: function(row, data) {
36 this.scrub_data(data);
37 this.add_date_separator(row, data);
Anand Doshia9ad4e32013-09-04 18:26:51 +053038 if(!data.add_class) data.add_class = "label-default";
Rushabh Mehta0db74a72012-12-07 15:47:32 +053039 $(row).append(repl('<div style="margin: 0px">\
Rushabh Mehtab62bbc62012-10-03 18:32:10 +053040 <span class="avatar avatar-small"><img src="%(imgsrc)s" /></span> \
Rushabh Mehtab4a2f4c2012-03-01 11:49:54 +053041 <span %(onclick)s class="label %(add_class)s">%(feed_type)s</span>\
42 %(link)s %(subject)s <span class="user-info">%(by)s</span></div>', data));
Rushabh Mehta12852e72012-02-29 15:11:06 +053043 },
44 scrub_data: function(data) {
Rushabh Mehta204e77d2012-02-29 19:09:20 +053045 data.by = wn.user_info(data.owner).fullname;
Rushabh Mehta24a69612012-12-11 15:58:19 +053046 data.imgsrc = wn.utils.get_file_link(wn.user_info(data.owner).image);
Rushabh Mehta12852e72012-02-29 15:11:06 +053047
48 // feedtype
49 if(!data.feed_type) {
Rushabh Mehta291449b2012-12-13 12:53:21 +053050 data.feed_type = wn._(data.doc_type);
Rushabh Mehta12852e72012-02-29 15:11:06 +053051 data.add_class = "label-info";
52 data.onclick = repl('onclick="window.location.href=\'#!List/%(feed_type)s\';"', data)
53 }
54
55 // color for comment
56 if(data.feed_type=='Comment') {
Anand Doshia9ad4e32013-09-04 18:26:51 +053057 data.add_class = "label-danger";
Rushabh Mehta12852e72012-02-29 15:11:06 +053058 }
59
Rushabh Mehta79ae1652012-02-29 15:23:25 +053060 if(data.feed_type=='Assignment') {
Rushabh Mehta1572adf2012-02-29 15:19:20 +053061 data.add_class = "label-warning";
62 }
63
Rushabh Mehta12852e72012-02-29 15:11:06 +053064 // link
65 if(data.doc_name && data.feed_type!='Login') {
Rushabh Mehta8956c672013-07-05 16:23:19 +053066 data.link = wn.format(data.doc_name, {"fieldtype":"Link", "options":data.doc_type})
Rushabh Mehta0db74a72012-12-07 15:47:32 +053067 } else {
68 data.link = "";
Rushabh Mehta12852e72012-02-29 15:11:06 +053069 }
70 },
71 add_date_separator: function(row, data) {
72 var date = dateutil.str_to_obj(data.modified);
73 var last = erpnext.last_feed_date;
74
Rushabh Mehtae45ffd62012-03-02 16:25:22 +053075 if((last && dateutil.obj_to_str(last) != dateutil.obj_to_str(date)) || (!last)) {
76 var diff = dateutil.get_day_diff(new Date(), date);
Rushabh Mehta12852e72012-02-29 15:11:06 +053077 if(diff < 1) {
78 pdate = 'Today';
Rushabh Mehtae45ffd62012-03-02 16:25:22 +053079 } else if(diff < 2) {
80 pdate = 'Yesterday';
81 } else {
Rushabh Mehta12852e72012-02-29 15:11:06 +053082 pdate = dateutil.global_date_format(date);
83 }
84 $(row).html(repl('<div class="date-sep">%(date)s</div>', {date: pdate}));
85 }
86 erpnext.last_feed_date = date;
87 }
88})