Rushabh Mehta | ad45e31 | 2013-11-20 12:59:58 +0530 | [diff] [blame] | 1 | // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors |
Rushabh Mehta | e67d1fb | 2013-08-05 14:59:54 +0530 | [diff] [blame] | 2 | // License: GNU General Public License v3. See license.txt |
| 3 | |
Rushabh Mehta | 12852e7 | 2012-02-29 15:11:06 +0530 | [diff] [blame] | 4 | wn.pages['activity'].onload = function(wrapper) { |
Rushabh Mehta | b394a25 | 2013-05-23 16:03:49 +0530 | [diff] [blame] | 5 | wn.ui.make_app_page({ |
| 6 | parent: wrapper, |
Bárbara Perretti | f6a6399 | 2013-10-07 14:06:23 -0300 | [diff] [blame] | 7 | title: wn._("Activity"), |
Rushabh Mehta | b394a25 | 2013-05-23 16:03:49 +0530 | [diff] [blame] | 8 | single_column: true |
| 9 | }) |
| 10 | wrapper.appframe.add_module_icon("Activity"); |
Anand Doshi | aea8204 | 2012-10-15 15:30:56 +0530 | [diff] [blame] | 11 | |
Rushabh Mehta | f81a64e | 2012-03-07 18:19:41 +0530 | [diff] [blame] | 12 | var list = new wn.ui.Listing({ |
Rushabh Mehta | 4f642e7 | 2013-11-13 16:55:38 +0530 | [diff] [blame] | 13 | hide_refresh: true, |
Rushabh Mehta | 2146fd1 | 2012-04-17 12:40:37 +0530 | [diff] [blame] | 14 | appframe: wrapper.appframe, |
Rushabh Mehta | 12852e7 | 2012-02-29 15:11:06 +0530 | [diff] [blame] | 15 | method: 'home.page.activity.activity.get_feed', |
Rushabh Mehta | b394a25 | 2013-05-23 16:03:49 +0530 | [diff] [blame] | 16 | parent: $(wrapper).find(".layout-main"), |
Rushabh Mehta | 12852e7 | 2012-02-29 15:11:06 +0530 | [diff] [blame] | 17 | render_row: function(row, data) { |
| 18 | new erpnext.ActivityFeed(row, data); |
| 19 | } |
| 20 | }); |
| 21 | list.run(); |
Rushabh Mehta | 4f642e7 | 2013-11-13 16:55:38 +0530 | [diff] [blame] | 22 | |
| 23 | wrapper.appframe.set_title_right("Refresh", function() { list.run(); }); |
Anand Doshi | aea8204 | 2012-10-15 15:30:56 +0530 | [diff] [blame] | 24 | |
| 25 | // Build Report Button |
| 26 | if(wn.boot.profile.can_get_report.indexOf("Feed")!=-1) { |
Rushabh Mehta | 4f642e7 | 2013-11-13 16:55:38 +0530 | [diff] [blame] | 27 | wrapper.appframe.add_primary_action(wn._('Build Report'), function() { |
Rushabh Mehta | 8fefeaf | 2013-06-04 11:23:42 +0530 | [diff] [blame] | 28 | wn.set_route('Report', "Feed"); |
Anand Doshi | aea8204 | 2012-10-15 15:30:56 +0530 | [diff] [blame] | 29 | }, 'icon-th') |
| 30 | } |
Rushabh Mehta | 12852e7 | 2012-02-29 15:11:06 +0530 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | erpnext.last_feed_date = false; |
| 34 | erpnext.ActivityFeed = Class.extend({ |
| 35 | init: function(row, data) { |
| 36 | this.scrub_data(data); |
| 37 | this.add_date_separator(row, data); |
Anand Doshi | a9ad4e3 | 2013-09-04 18:26:51 +0530 | [diff] [blame] | 38 | if(!data.add_class) data.add_class = "label-default"; |
Rushabh Mehta | 0db74a7 | 2012-12-07 15:47:32 +0530 | [diff] [blame] | 39 | $(row).append(repl('<div style="margin: 0px">\ |
Rushabh Mehta | b62bbc6 | 2012-10-03 18:32:10 +0530 | [diff] [blame] | 40 | <span class="avatar avatar-small"><img src="%(imgsrc)s" /></span> \ |
Rushabh Mehta | b4a2f4c | 2012-03-01 11:49:54 +0530 | [diff] [blame] | 41 | <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 Mehta | 12852e7 | 2012-02-29 15:11:06 +0530 | [diff] [blame] | 43 | }, |
| 44 | scrub_data: function(data) { |
Rushabh Mehta | 204e77d | 2012-02-29 19:09:20 +0530 | [diff] [blame] | 45 | data.by = wn.user_info(data.owner).fullname; |
Rushabh Mehta | 24a6961 | 2012-12-11 15:58:19 +0530 | [diff] [blame] | 46 | data.imgsrc = wn.utils.get_file_link(wn.user_info(data.owner).image); |
Rushabh Mehta | 12852e7 | 2012-02-29 15:11:06 +0530 | [diff] [blame] | 47 | |
| 48 | // feedtype |
| 49 | if(!data.feed_type) { |
Rushabh Mehta | 291449b | 2012-12-13 12:53:21 +0530 | [diff] [blame] | 50 | data.feed_type = wn._(data.doc_type); |
Rushabh Mehta | 12852e7 | 2012-02-29 15:11:06 +0530 | [diff] [blame] | 51 | 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 Doshi | a9ad4e3 | 2013-09-04 18:26:51 +0530 | [diff] [blame] | 57 | data.add_class = "label-danger"; |
Rushabh Mehta | 12852e7 | 2012-02-29 15:11:06 +0530 | [diff] [blame] | 58 | } |
| 59 | |
Rushabh Mehta | 79ae165 | 2012-02-29 15:23:25 +0530 | [diff] [blame] | 60 | if(data.feed_type=='Assignment') { |
Rushabh Mehta | 1572adf | 2012-02-29 15:19:20 +0530 | [diff] [blame] | 61 | data.add_class = "label-warning"; |
| 62 | } |
| 63 | |
Rushabh Mehta | 12852e7 | 2012-02-29 15:11:06 +0530 | [diff] [blame] | 64 | // link |
| 65 | if(data.doc_name && data.feed_type!='Login') { |
Rushabh Mehta | 8956c67 | 2013-07-05 16:23:19 +0530 | [diff] [blame] | 66 | data.link = wn.format(data.doc_name, {"fieldtype":"Link", "options":data.doc_type}) |
Rushabh Mehta | 0db74a7 | 2012-12-07 15:47:32 +0530 | [diff] [blame] | 67 | } else { |
| 68 | data.link = ""; |
Rushabh Mehta | 12852e7 | 2012-02-29 15:11:06 +0530 | [diff] [blame] | 69 | } |
| 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 Mehta | e45ffd6 | 2012-03-02 16:25:22 +0530 | [diff] [blame] | 75 | if((last && dateutil.obj_to_str(last) != dateutil.obj_to_str(date)) || (!last)) { |
| 76 | var diff = dateutil.get_day_diff(new Date(), date); |
Rushabh Mehta | 12852e7 | 2012-02-29 15:11:06 +0530 | [diff] [blame] | 77 | if(diff < 1) { |
| 78 | pdate = 'Today'; |
Rushabh Mehta | e45ffd6 | 2012-03-02 16:25:22 +0530 | [diff] [blame] | 79 | } else if(diff < 2) { |
| 80 | pdate = 'Yesterday'; |
| 81 | } else { |
Rushabh Mehta | 12852e7 | 2012-02-29 15:11:06 +0530 | [diff] [blame] | 82 | 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 | }) |