blob: 8d451939cc77bc459857038aff83d760cb1b7a1e [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);
Anand Doshia9ad4e32013-09-04 18:26:51 +053035 if(!data.add_class) data.add_class = "label-default";
Rushabh Mehta0db74a72012-12-07 15:47:32 +053036 $(row).append(repl('<div style="margin: 0px">\
Rushabh Mehtab62bbc62012-10-03 18:32:10 +053037 <span class="avatar avatar-small"><img src="%(imgsrc)s" /></span> \
Rushabh Mehtab4a2f4c2012-03-01 11:49:54 +053038 <span %(onclick)s class="label %(add_class)s">%(feed_type)s</span>\
39 %(link)s %(subject)s <span class="user-info">%(by)s</span></div>', data));
Rushabh Mehta12852e72012-02-29 15:11:06 +053040 },
41 scrub_data: function(data) {
Rushabh Mehta204e77d2012-02-29 19:09:20 +053042 data.by = wn.user_info(data.owner).fullname;
Rushabh Mehta24a69612012-12-11 15:58:19 +053043 data.imgsrc = wn.utils.get_file_link(wn.user_info(data.owner).image);
Rushabh Mehta12852e72012-02-29 15:11:06 +053044
45 // feedtype
46 if(!data.feed_type) {
Rushabh Mehta291449b2012-12-13 12:53:21 +053047 data.feed_type = wn._(data.doc_type);
Rushabh Mehta12852e72012-02-29 15:11:06 +053048 data.add_class = "label-info";
49 data.onclick = repl('onclick="window.location.href=\'#!List/%(feed_type)s\';"', data)
50 }
51
52 // color for comment
53 if(data.feed_type=='Comment') {
Anand Doshia9ad4e32013-09-04 18:26:51 +053054 data.add_class = "label-danger";
Rushabh Mehta12852e72012-02-29 15:11:06 +053055 }
56
Rushabh Mehta79ae1652012-02-29 15:23:25 +053057 if(data.feed_type=='Assignment') {
Rushabh Mehta1572adf2012-02-29 15:19:20 +053058 data.add_class = "label-warning";
59 }
60
Rushabh Mehta12852e72012-02-29 15:11:06 +053061 // link
62 if(data.doc_name && data.feed_type!='Login') {
Rushabh Mehta8956c672013-07-05 16:23:19 +053063 data.link = wn.format(data.doc_name, {"fieldtype":"Link", "options":data.doc_type})
Rushabh Mehta0db74a72012-12-07 15:47:32 +053064 } else {
65 data.link = "";
Rushabh Mehta12852e72012-02-29 15:11:06 +053066 }
67 },
68 add_date_separator: function(row, data) {
69 var date = dateutil.str_to_obj(data.modified);
70 var last = erpnext.last_feed_date;
71
Rushabh Mehtae45ffd62012-03-02 16:25:22 +053072 if((last && dateutil.obj_to_str(last) != dateutil.obj_to_str(date)) || (!last)) {
73 var diff = dateutil.get_day_diff(new Date(), date);
Rushabh Mehta12852e72012-02-29 15:11:06 +053074 if(diff < 1) {
75 pdate = 'Today';
Rushabh Mehtae45ffd62012-03-02 16:25:22 +053076 } else if(diff < 2) {
77 pdate = 'Yesterday';
78 } else {
Rushabh Mehta12852e72012-02-29 15:11:06 +053079 pdate = dateutil.global_date_format(date);
80 }
81 $(row).html(repl('<div class="date-sep">%(date)s</div>', {date: pdate}));
82 }
83 erpnext.last_feed_date = date;
84 }
85})