2012-02-28 12:10:13 +00:00
|
|
|
// ERPNext - web based ERP (http://erpnext.com)
|
|
|
|
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2012-02-27 12:33:54 +00:00
|
|
|
wn.provide('erpnext.messages');
|
|
|
|
|
|
|
|
wn.pages.messages.onload = function(wrapper) {
|
|
|
|
erpnext.messages.show_active_users();
|
|
|
|
erpnext.messages.make_list();
|
2012-05-03 05:14:44 +00:00
|
|
|
erpnext.update_messages('reset'); //Resets notification icons
|
2012-02-27 12:33:54 +00:00
|
|
|
|
|
|
|
// post message
|
|
|
|
$('#message-post').click(function() {
|
|
|
|
var txt = $('#message-post-text').val();
|
|
|
|
if(txt) {
|
|
|
|
wn.call({
|
|
|
|
module:'utilities',
|
|
|
|
page:'messages',
|
|
|
|
method:'post',
|
|
|
|
args: {
|
|
|
|
txt: txt,
|
|
|
|
contact: erpnext.messages.contact
|
|
|
|
},
|
|
|
|
callback:function(r,rt) {
|
|
|
|
$('#message-post-text').val('')
|
|
|
|
erpnext.messages.list.run();
|
|
|
|
},
|
|
|
|
btn: this
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// enable, disable button
|
2012-03-22 08:14:04 +00:00
|
|
|
$('#message-post-text').keyup(function(e) {
|
2012-02-27 12:33:54 +00:00
|
|
|
if($(this).val()) {
|
|
|
|
$('#message-post').attr('disabled', false);
|
|
|
|
} else {
|
|
|
|
$('#message-post').attr('disabled', true);
|
|
|
|
}
|
2012-03-22 08:14:04 +00:00
|
|
|
|
|
|
|
if(e.which==13) {
|
|
|
|
$('#message-post').click();
|
|
|
|
}
|
2012-02-27 12:33:54 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2012-03-22 08:14:04 +00:00
|
|
|
$(wn.pages.messages).bind('show', function() {
|
2012-02-27 12:33:54 +00:00
|
|
|
erpnext.messages.show();
|
2012-03-22 08:14:04 +00:00
|
|
|
setTimeout(erpnext.messages.refresh, 7000);
|
2012-02-27 13:26:31 +00:00
|
|
|
$('#message-post-text').focus();
|
2012-03-22 08:14:04 +00:00
|
|
|
})
|
2012-02-27 12:33:54 +00:00
|
|
|
|
|
|
|
erpnext.messages = {
|
|
|
|
show: function() {
|
|
|
|
var contact = erpnext.messages.get_contact();
|
|
|
|
|
|
|
|
// can't send message to self
|
|
|
|
$(wn.pages.messages).find('.well').toggle(contact==user ? false : true);
|
|
|
|
|
|
|
|
$(wn.pages.messages).find('h1:first').html('Messages: '
|
2012-02-29 13:39:20 +00:00
|
|
|
+ (user==contact ? 'From everyone' : wn.user_info(contact).fullname));
|
2012-02-27 12:33:54 +00:00
|
|
|
|
|
|
|
erpnext.messages.contact = contact;
|
|
|
|
erpnext.messages.list.opts.args.contact = contact;
|
|
|
|
erpnext.messages.list.run();
|
|
|
|
|
|
|
|
},
|
|
|
|
// check for updates every 5 seconds if page is active
|
|
|
|
refresh: function() {
|
2012-03-22 08:14:04 +00:00
|
|
|
setTimeout(erpnext.messages.refresh, 7000);
|
|
|
|
if(wn.container.page.label != 'Messages') return;
|
2012-02-27 12:33:54 +00:00
|
|
|
erpnext.messages.show();
|
|
|
|
},
|
|
|
|
get_contact: function() {
|
|
|
|
var route = location.hash;
|
|
|
|
if(route.indexOf('/')!=-1) {
|
|
|
|
var name = decodeURIComponent(route.split('/')[1]);
|
|
|
|
if(name.indexOf('__at__')!=-1) {
|
|
|
|
name = name.replace('__at__', '@');
|
|
|
|
}
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
return user;
|
|
|
|
},
|
|
|
|
make_list: function() {
|
2012-03-07 12:49:41 +00:00
|
|
|
erpnext.messages.list = new wn.ui.Listing({
|
2012-02-27 12:33:54 +00:00
|
|
|
parent: $('#message-list').get(0),
|
|
|
|
method: 'utilities.page.messages.messages.get_list',
|
|
|
|
args: {
|
|
|
|
contact: null
|
|
|
|
},
|
|
|
|
render_row: function(wrapper, data) {
|
2012-03-22 08:14:04 +00:00
|
|
|
$(wrapper).removeClass('list-row');
|
|
|
|
|
2012-02-27 12:33:54 +00:00
|
|
|
data.creation = dateutil.comment_when(data.creation);
|
2012-02-29 13:39:20 +00:00
|
|
|
data.comment_by_fullname = wn.user_info(data.owner).fullname;
|
2012-02-27 12:33:54 +00:00
|
|
|
|
2012-02-27 13:26:31 +00:00
|
|
|
data.reply_html = '';
|
2012-02-27 12:33:54 +00:00
|
|
|
if(data.owner==user) {
|
|
|
|
data.cls = 'message-self';
|
|
|
|
data.comment_by_fullname = 'You';
|
2012-02-27 13:26:31 +00:00
|
|
|
data.delete_html = repl('<a class="close" \
|
|
|
|
onclick="erpnext.messages.delete(this)"\
|
2012-02-27 13:11:11 +00:00
|
|
|
data-name="%(name)s">×</a>', data);
|
2012-02-27 12:33:54 +00:00
|
|
|
} else {
|
2012-02-27 13:11:11 +00:00
|
|
|
data.cls = 'message-other';
|
|
|
|
data.delete_html = '';
|
2012-02-27 13:26:31 +00:00
|
|
|
if(erpnext.messages.contact==user) {
|
|
|
|
data.reply_html = repl('<a href="#!messages/%(owner)s">\
|
|
|
|
<i class="icon-share-alt"></i> Reply</a>', data)
|
|
|
|
}
|
2012-02-27 12:33:54 +00:00
|
|
|
}
|
|
|
|
|
2012-02-27 13:11:11 +00:00
|
|
|
wrapper.innerHTML = repl('<div class="message %(cls)s">%(delete_html)s\
|
|
|
|
<b>%(comment)s</b>\
|
2012-02-27 13:26:31 +00:00
|
|
|
<div class="help">by %(comment_by_fullname)s, %(creation)s</div>\
|
|
|
|
%(reply_html)s</div>\
|
2012-02-27 12:33:54 +00:00
|
|
|
<div style="clear: both;"></div>', data);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2012-02-27 13:11:11 +00:00
|
|
|
delete: function(ele) {
|
|
|
|
$(ele).parent().css('opacity', 0.6);
|
|
|
|
wn.call({
|
|
|
|
method:'utilities.page.messages.messages.delete',
|
|
|
|
args: {name : $(ele).attr('data-name')},
|
|
|
|
callback: function() {
|
|
|
|
$(ele).parent().toggle(false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2012-02-27 12:33:54 +00:00
|
|
|
show_active_users: function() {
|
|
|
|
wn.call({
|
|
|
|
module:'utilities',
|
|
|
|
page:'messages',
|
|
|
|
method:'get_active_users',
|
|
|
|
callback: function(r,rt) {
|
|
|
|
var $body = $(wn.pages.messages).find('.section-body');
|
|
|
|
for(var i in r.message) {
|
|
|
|
var p = r.message[i];
|
2012-02-29 13:39:20 +00:00
|
|
|
p.fullname = wn.user_info(p.name).fullname;
|
2012-02-27 12:33:54 +00:00
|
|
|
p.name = p.name.replace('@', '__at__');
|
|
|
|
$body.append(repl('<div class="section-item">\
|
|
|
|
<a href="#!messages/%(name)s">%(fullname)s</a></div>', p))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|