Rushabh Mehta | aaf86ba | 2012-02-28 17:40:13 +0530 | [diff] [blame] | 1 | # ERPNext - web based ERP (http://erpnext.com) |
| 2 | # Copyright (C) 2012 Web Notes Technologies Pvt Ltd |
| 3 | # |
| 4 | # This program is free software: you can redistribute it and/or modify |
| 5 | # it under the terms of the GNU General Public License as published by |
| 6 | # the Free Software Foundation, either version 3 of the License, or |
| 7 | # (at your option) any later version. |
| 8 | # |
| 9 | # This program is distributed in the hope that it will be useful, |
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | # GNU General Public License for more details. |
| 13 | # |
| 14 | # You should have received a copy of the GNU General Public License |
| 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | |
Rushabh Mehta | fdea966 | 2012-02-27 18:03:54 +0530 | [diff] [blame] | 17 | import webnotes |
| 18 | |
| 19 | @webnotes.whitelist() |
| 20 | def get_list(arg=None): |
| 21 | """get list of messages""" |
| 22 | webnotes.form_dict['limit_start'] = int(webnotes.form_dict['limit_start']) |
| 23 | webnotes.form_dict['limit_page_length'] = int(webnotes.form_dict['limit_page_length']) |
| 24 | webnotes.form_dict['user'] = webnotes.session['user'] |
| 25 | |
| 26 | if webnotes.form_dict['contact'] == webnotes.session['user']: |
Rushabh Mehta | 07a36a4 | 2012-02-27 18:17:57 +0530 | [diff] [blame] | 27 | # set all messages as read |
| 28 | webnotes.conn.sql("""UPDATE `tabComment Widget Record` |
| 29 | set docstatus = 1 where comment_doctype in ('My Company', 'Message') |
| 30 | and comment_docname = %s |
| 31 | """, webnotes.user.name) |
| 32 | |
| 33 | # return messages |
Rushabh Mehta | fdea966 | 2012-02-27 18:03:54 +0530 | [diff] [blame] | 34 | return webnotes.conn.sql("""select * from `tabComment Widget Record` |
| 35 | where (owner=%(contact)s or comment_docname=%(user)s) |
| 36 | and comment_doctype in ('My Company', 'Message') |
| 37 | order by creation desc |
| 38 | limit %(limit_start)s, %(limit_page_length)s""", webnotes.form_dict, as_dict=1) |
| 39 | else: |
| 40 | return webnotes.conn.sql("""select * from `tabComment Widget Record` |
| 41 | where (owner=%(contact)s and comment_docname=%(user)s) |
| 42 | or (owner=%(user)s and comment_docname=%(contact)s) |
| 43 | and comment_doctype in ('My Company', 'Message') |
| 44 | order by creation desc |
| 45 | limit %(limit_start)s, %(limit_page_length)s""", webnotes.form_dict, as_dict=1) |
| 46 | |
| 47 | |
| 48 | @webnotes.whitelist() |
| 49 | def get_active_users(arg=None): |
| 50 | return webnotes.conn.sql("""select name from tabProfile |
Rushabh Mehta | b6023a4 | 2012-03-01 13:47:51 +0530 | [diff] [blame] | 51 | where ifnull(enabled,0)=1 and |
| 52 | docstatus < 2 and |
Rushabh Mehta | fdea966 | 2012-02-27 18:03:54 +0530 | [diff] [blame] | 53 | name not in ('Administrator', 'Guest') |
| 54 | order by first_name""", as_dict=1) |
| 55 | |
| 56 | @webnotes.whitelist() |
| 57 | def post(arg=None): |
| 58 | """post message""" |
Anand Doshi | 20f63da | 2012-03-08 12:10:51 +0530 | [diff] [blame] | 59 | if arg: |
| 60 | import json |
| 61 | arg = json.loads(arg) |
| 62 | else: |
| 63 | arg = {} |
| 64 | arg.update(webnotes.form_dict) |
Rushabh Mehta | fdea966 | 2012-02-27 18:03:54 +0530 | [diff] [blame] | 65 | from webnotes.model.doc import Document |
| 66 | d = Document('Comment Widget Record') |
| 67 | d.comment = arg['txt'] |
| 68 | d.comment_docname = arg['contact'] |
| 69 | d.comment_doctype = 'Message' |
| 70 | d.save() |
Rushabh Mehta | ef29e55 | 2012-02-27 18:41:11 +0530 | [diff] [blame] | 71 | |
| 72 | @webnotes.whitelist() |
| 73 | def delete(arg=None): |
| 74 | webnotes.conn.sql("""delete from `tabComment Widget Record` where name=%s""", |
| 75 | webnotes.form_dict['name']); |
Anand Doshi | eb55df0 | 2012-03-08 12:06:27 +0530 | [diff] [blame] | 76 | |