From b7a638ccde0a0a469d54e8285d662ffae9e662fd Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 13 Apr 2011 14:07:56 +0200 Subject: [PATCH 1/8] [BOOM] deactivate all addons, remove links to addons stuff from base, do not belong there bzr revid: xmo@openerp.com-20110413120756-md9lg1rgehoyg4mc --- addons/base/static/src/base.html | 34 ---------------- addons/base/static/src/js/base.js | 3 -- addons/base/static/src/js/chrome.js | 4 +- addons/base/static/src/xml/base.xml | 48 ----------------------- addons/base_calendar/__openerp__.py | 61 +++-------------------------- addons/base_diagram/__openerp__.py | 2 +- addons/base_gantt/__openerp__.py | 1 + addons/web_chat/__openerp__.py | 2 +- openerpweb/openerpweb.py | 9 +++-- 9 files changed, 16 insertions(+), 148 deletions(-) diff --git a/addons/base/static/src/base.html b/addons/base/static/src/base.html index ec33df12bec..83fbfcecefc 100644 --- a/addons/base/static/src/base.html +++ b/addons/base/static/src/base.html @@ -23,33 +23,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/addons/base/static/src/js/base.js b/addons/base/static/src/js/base.js index 3a5bd2a2915..504f5ca744d 100644 --- a/addons/base/static/src/js/base.js +++ b/addons/base/static/src/js/base.js @@ -126,9 +126,6 @@ openerp.base = function(instance) { openerp.base.search(instance); openerp.base.list(instance); openerp.base.form(instance); - openerp.base.calendar(instance); - openerp.base.gantt(instance); - openerp.base.diagram(instance); }; // vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax: diff --git a/addons/base/static/src/js/chrome.js b/addons/base/static/src/js/chrome.js index c4c55f2728d..6a46021edd4 100644 --- a/addons/base/static/src/js/chrome.js +++ b/addons/base/static/src/js/chrome.js @@ -491,7 +491,7 @@ openerp.base.Controller = openerp.base.BasicController.extend( /** @lends opener controller_manifest: { register: null, template: "", - element_post_prefix: false, + element_post_prefix: false }, /** * Controller registry, @@ -702,7 +702,7 @@ openerp.base.CrashManager = openerp.base.Controller.extend({ openerp.base.Loading = openerp.base.Controller.extend({ controller_manifest: { - register: ["Loading"], + register: ["Loading"] }, init: function(session, element_id) { this._super(session, element_id); diff --git a/addons/base/static/src/xml/base.xml b/addons/base/static/src/xml/base.xml index 9f7ddc49a7b..cbb90ca9e2e 100644 --- a/addons/base/static/src/xml/base.xml +++ b/addons/base/static/src/xml/base.xml @@ -231,10 +231,6 @@ - -

-
-

@@ -574,48 +570,4 @@

- -

- - - - - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -

- - - - - -
-
-
-
-
-
diff --git a/addons/base_calendar/__openerp__.py b/addons/base_calendar/__openerp__.py index e77da6a5629..3f4d8ee314d 100644 --- a/addons/base_calendar/__openerp__.py +++ b/addons/base_calendar/__openerp__.py @@ -1,57 +1,8 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2010 Tiny SPRL (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero 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 Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - { - "name" : "Basic Calendar Functionality", - "version" : "1.0", - "depends" : ["base"], - 'description': """ -This is a full-featured calendar system. -======================================== - -It supports: - - Calendar of events - - Alerts (create requests) - - Recurring events - - Invitations to people""", - "author" : "OpenERP SA", - 'category': 'Tools', - 'website': 'http://www.openerp.com', - "init_xml" : [ - 'base_calendar_data.xml' - ], - "demo_xml" : [], - "update_xml" : [ - 'security/calendar_security.xml', - 'security/ir.model.access.csv', - 'wizard/calendar_event_edit_all_view.xml', - 'wizard/base_calendar_invite_attendee_view.xml', - 'wizard/base_calendar_set_exrule_view.xml', - 'base_calendar_view.xml' - ], - "test" : ['test/base_calendar_test.yml'], - "installable" : True, - "active" : False, - "certificate" : "00694071962960352821", - 'images': ['images/base_calendar1.jpeg','images/base_calendar2.jpeg','images/base_calendar3.jpeg','images/base_calendar4.jpeg',], + "name": "Hello", + "version": "2.0", + "depends": [], + "js": ["static/*/js/*.js"], + "css": [], + 'active': False } - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/base_diagram/__openerp__.py b/addons/base_diagram/__openerp__.py index fb2a849f630..92b768896f9 100644 --- a/addons/base_diagram/__openerp__.py +++ b/addons/base_diagram/__openerp__.py @@ -2,5 +2,5 @@ "name" : "OpenERP Web base Diagram", "version" : "2.0", "depends" : [], - 'active': True, + 'active': False, } diff --git a/addons/base_gantt/__openerp__.py b/addons/base_gantt/__openerp__.py index d3b4dbd3885..afd1f402b59 100644 --- a/addons/base_gantt/__openerp__.py +++ b/addons/base_gantt/__openerp__.py @@ -4,4 +4,5 @@ "depends": [], "js": ["static/*/js/*.js"], "css": [], + 'active': False } diff --git a/addons/web_chat/__openerp__.py b/addons/web_chat/__openerp__.py index 132986ff90d..9c9ee6f3b2f 100644 --- a/addons/web_chat/__openerp__.py +++ b/addons/web_chat/__openerp__.py @@ -4,5 +4,5 @@ "depends": [], "js": ["static/src/web_chat.js"], "css": [], - 'active': True, + 'active': False, } diff --git a/openerpweb/openerpweb.py b/openerpweb/openerpweb.py index 8423dc878ab..027a86a8f78 100644 --- a/openerpweb/openerpweb.py +++ b/openerpweb/openerpweb.py @@ -436,10 +436,11 @@ class Root(object): manifest_path = os.path.join(path_addons, i, '__openerp__.py') if os.path.isfile(manifest_path): manifest = eval(open(manifest_path).read()) - print "Loading", i - m = __import__(i) - addons_module[i] = m - addons_manifest[i] = manifest + if manifest.get('active', True): + print "Loading", i + m = __import__(i) + addons_module[i] = m + addons_manifest[i] = manifest for k, v in controllers_class.items(): if k not in controllers_object: o = v() From b4cd776b253be161fafa577f7e759181d8fb9032 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 13 Apr 2011 14:50:42 +0200 Subject: [PATCH 2/8] [FIX] correctly load calendar addon * Fix loading of active modules (don't hardcode list) * Implement loading of CSS files via css list * Fix Calendar addon - Add list of JS files to descriptor - Add list of CSS files to descriptor - Have calendar load its own qweb template file - Put calendar in the correct namespace (openerp.base_calendar) instead of a nonsensical one bzr revid: xmo@openerp.com-20110413125042-feiimul8617a51d6 --- addons/base/controllers/main.py | 24 +++++++++----- addons/base/static/src/js/chrome.js | 23 +++++++++---- addons/base_calendar/__openerp__.py | 11 ++++--- .../base_calendar/static/src/js/calendar.js | 6 ++-- .../static/src/xml/base_calendar.xml | 33 +++++++++++++++++++ openerpweb/openerpweb.py | 9 +++-- 6 files changed, 79 insertions(+), 27 deletions(-) create mode 100644 addons/base_calendar/static/src/xml/base_calendar.xml diff --git a/addons/base/controllers/main.py b/addons/base/controllers/main.py index 8a2c31b42eb..bdedb85e63d 100644 --- a/addons/base/controllers/main.py +++ b/addons/base/controllers/main.py @@ -58,13 +58,17 @@ class Xml2Json: class Session(openerpweb.Controller): _cp_path = "/base/session" - def manifest_glob(self, modlist, key): + def manifest_glob(self, addons, key): files = [] - for i in modlist: - globlist = openerpweb.addons_manifest.get(i, {}).get(key, []) - for j in globlist: - for k in glob.glob(os.path.join(openerpweb.path_addons, i, j)): - files.append(k[len(openerpweb.path_addons):]) + for addon in addons: + globlist = openerpweb.addons_manifest.get(addon, {}).get(key, []) + + files.extend([ + resource_path[len(openerpweb.path_addons):] + for pattern in globlist + for resource_path in glob.glob(os.path.join( + openerpweb.path_addons, addon, pattern)) + ]) return files def concat_files(self, file_list): @@ -96,14 +100,16 @@ class Session(openerpweb.Controller): @openerpweb.jsonrequest def modules(self, req): - return {"modules": ["base", "base_hello", "base_calendar", "base_gantt"]} + return {"modules": [name + for name, manifest in openerpweb.addons_manifest.iteritems() + if manifest.get('active', True)]} @openerpweb.jsonrequest - def csslist(self, req, mods='base,base_hello'): + def csslist(self, req, mods='base'): return {'files': self.manifest_glob(mods.split(','), 'css')} @openerpweb.jsonrequest - def jslist(self, req, mods='base,base_hello'): + def jslist(self, req, mods='base'): return {'files': self.manifest_glob(mods.split(','), 'js')} def css(self, req, mods='base,base_hello'): diff --git a/addons/base/static/src/js/chrome.js b/addons/base/static/src/js/chrome.js index 6a46021edd4..77cdd264d20 100644 --- a/addons/base/static/src/js/chrome.js +++ b/addons/base/static/src/js/chrome.js @@ -450,10 +450,22 @@ openerp.base.Session = openerp.base.BasicController.extend( /** @lends openerp.b var self = this; this.rpc('/base/session/modules', {}, function(result) { self.module_list = result['modules']; - self.rpc('/base/session/jslist', {"mods": self.module_list.join(',')}, self.debug ? self.do_load_modules_debug : self.do_load_modules_prod); + var modules = self.module_list.join(','); + self.rpc('/base/session/csslist', {mods: modules}, self.do_load_css); + self.rpc('/base/session/jslist', {"mods": modules}, self.debug ? self.do_load_modules_debug : self.do_load_modules_prod); openerp._modules_loaded = true; }); }, + do_load_css: function (result) { + console.log('loading CSS files'); + _.each(result.files, function (file) { + $('head').append($('', { + 'href': file, + 'rel': 'stylesheet', + 'type': 'text/css' + })); + }); + }, do_load_modules_debug: function(result) { $LAB.setOptions({AlwaysPreserveOrder: true}) .script(result.files) @@ -466,16 +478,15 @@ openerp.base.Session = openerp.base.BasicController.extend( /** @lends openerp.b // use $.getScript(‘your_3rd_party-script.js’); ? i want to keep lineno ! }, on_modules_loaded: function() { - var self = this; - for(var j=0; j + +

+ + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ diff --git a/openerpweb/openerpweb.py b/openerpweb/openerpweb.py index 027a86a8f78..8423dc878ab 100644 --- a/openerpweb/openerpweb.py +++ b/openerpweb/openerpweb.py @@ -436,11 +436,10 @@ class Root(object): manifest_path = os.path.join(path_addons, i, '__openerp__.py') if os.path.isfile(manifest_path): manifest = eval(open(manifest_path).read()) - if manifest.get('active', True): - print "Loading", i - m = __import__(i) - addons_module[i] = m - addons_manifest[i] = manifest + print "Loading", i + m = __import__(i) + addons_module[i] = m + addons_manifest[i] = manifest for k, v in controllers_class.items(): if k not in controllers_object: o = v() From ffefcd76ed7c3f56692eb7f22aeb3e03fdabe291 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 13 Apr 2011 15:31:57 +0200 Subject: [PATCH 3/8] [IMP] documentation of addons structure and namespacing bzr revid: xmo@openerp.com-20110413133157-pin980f20ovwi4bw --- doc/source/addons.rst | 60 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/doc/source/addons.rst b/doc/source/addons.rst index 548e8ad461d..bba57b40bd0 100644 --- a/doc/source/addons.rst +++ b/doc/source/addons.rst @@ -1,6 +1,10 @@ Developing OpenERP Web Addons ============================= +An OpenERP Web addon is simply a Python package with an openerp +descriptor (a ``__openerp__.py`` file) which follows a few structural +and namespacing rules. + Structure --------- @@ -50,6 +54,62 @@ Structure ``test/`` The directories in which all tests for the addon are located. +Some of these are guidelines (and not enforced by code), but it's +suggested that these be followed. Code which does not fit into these +categories can go wherever deemed suitable. + +Namespacing +----------- + +Python +++++++ + +Because addons are also Python packages, they're inherently namespaced +and nothing special needs to be done on that front. + +JavaScript +++++++++++ + +The JavaScript side of an addon has to live in the namespace +``openerp.$addon_name``. For instance, everything created by the addon +``base`` lives in ``openerp.base``. + +The root namespace of the addon is a function which takes a single +parameter ``openerp``, which is an OpenERP client instance. Objects +(as well as functions, registry instances, etc...) should be added on +the correct namespace on that object. + +The root function will be called by the OpenERP Web client when +initializing the addon. + +.. code-block:: javascript + + // root namespace of the openerp.example addon + /** @namespace */ + openerp.example = function (openerp) { + // basic initialization code (e.g. templates loading) + openerp.example.SomeClass = Class.extend( + /** @lends openerp.example.SomeClass# */{ + /** + * Description for SomeClass's constructor here + * + * @constructs + */ + init: function () { + // SomeClass initialization code + } + // rest of SomeClass + }); + + // access an object in an other addon namespace to replace it + openerp.base.SearchView = openerp.base.SearchView.extend({ + init: function () { + this._super.apply(this, arguments); + console.log('Search view initialized'); + } + }); + } + .. _addons-testing: Testing From 26ddfe235d2f79ec9dc91093407af643c9ac7e75 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 13 Apr 2011 15:32:07 +0200 Subject: [PATCH 4/8] [FIX] namespacing of base_calendar addon bzr revid: xmo@openerp.com-20110413133207-k4d53w0eznwtqoec --- addons/base_calendar/static/src/js/calendar.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/base_calendar/static/src/js/calendar.js b/addons/base_calendar/static/src/js/calendar.js index 3a2981974fd..96a7fad8178 100644 --- a/addons/base_calendar/static/src/js/calendar.js +++ b/addons/base_calendar/static/src/js/calendar.js @@ -4,8 +4,8 @@ openerp.base_calendar = function(openerp) { QWeb.add_template('/base_calendar/static/src/xml/base_calendar.xml'); -openerp.base.views.add('calendar', 'openerp.base.CalendarView'); -openerp.base.CalendarView = openerp.base.Controller.extend({ +openerp.base.views.add('calendar', 'openerp.base_calendar.CalendarView'); +openerp.base_calendar.CalendarView = openerp.base.Controller.extend({ // Dhtmlx scheduler ? init: function(view_manager, session, element_id, dataset, view_id){ this._super(session, element_id); From a83bd29ada53e574a9ce7a402b0623c3ace74fef Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 13 Apr 2011 16:07:35 +0200 Subject: [PATCH 5/8] [IMP] document automatic binding of do_ and on_ methods of BasicController subclasses bzr revid: xmo@openerp.com-20110413140735-hc8nbxxos4yl11xj --- doc/source/addons.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/doc/source/addons.rst b/doc/source/addons.rst index bba57b40bd0..bca568f58df 100644 --- a/doc/source/addons.rst +++ b/doc/source/addons.rst @@ -110,6 +110,23 @@ initializing the addon. }); } +Utility behaviors +----------------- + +JavaScript +++++++++++ + +* All javascript objects inheriting from + :js:class:`openerp.base.BasicConroller` will have all methods + starting with ``on_`` or ``do_`` bound to their ``this``. This means + they don't have to be manually bound (via ``_.bind`` or ``$.proxy``) + in order to be useable as bound event handlers (event handlers + keeping their object as ``this`` rather than taking whatever + ``this`` object they were called with). + + Beware that this is only valid for methods starting with ``do_`` and + ``on_``, any other method will have to be bound manually. + .. _addons-testing: Testing From bc2b83e883ae068b35c4310693205b11b52e97c4 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 13 Apr 2011 16:20:01 +0200 Subject: [PATCH 6/8] [FIX] gantt addon so it loads correctly Also remove leftover debugging log in chrome, and fix dependencies listing for calendar bzr revid: xmo@openerp.com-20110413142001-5dpxoava5a0cwmq7 --- addons/base/static/src/js/chrome.js | 1 - addons/base_calendar/__openerp__.py | 2 +- addons/base_gantt/__openerp__.py | 12 ++++++++---- addons/base_gantt/static/src/{ => js}/gantt.js | 9 +++++---- addons/base_gantt/static/src/xml/base_gantt.xml | 15 +++++++++++++++ 5 files changed, 29 insertions(+), 10 deletions(-) rename addons/base_gantt/static/src/{ => js}/gantt.js (97%) create mode 100644 addons/base_gantt/static/src/xml/base_gantt.xml diff --git a/addons/base/static/src/js/chrome.js b/addons/base/static/src/js/chrome.js index 77cdd264d20..4391fcf6f4e 100644 --- a/addons/base/static/src/js/chrome.js +++ b/addons/base/static/src/js/chrome.js @@ -457,7 +457,6 @@ openerp.base.Session = openerp.base.BasicController.extend( /** @lends openerp.b }); }, do_load_css: function (result) { - console.log('loading CSS files'); _.each(result.files, function (file) { $('head').append($('', { 'href': file, diff --git a/addons/base_calendar/__openerp__.py b/addons/base_calendar/__openerp__.py index 8b1d0ca6473..5688c0e05b5 100644 --- a/addons/base_calendar/__openerp__.py +++ b/addons/base_calendar/__openerp__.py @@ -1,7 +1,7 @@ { "name": "Base calendar", "version": "2.0", - "depends": [], + "depends": ['base'], "js": [ 'static/lib/dhtmlxScheduler/codebase/dhtmlxscheduler.js', 'static/src/js/calendar.js' diff --git a/addons/base_gantt/__openerp__.py b/addons/base_gantt/__openerp__.py index afd1f402b59..55cec2c0863 100644 --- a/addons/base_gantt/__openerp__.py +++ b/addons/base_gantt/__openerp__.py @@ -1,8 +1,12 @@ { "name": "Base Gantt", "version": "2.0", - "depends": [], - "js": ["static/*/js/*.js"], - "css": [], - 'active': False + "depends": ['base'], + "js": [ + 'static/lib/dhtmlxGantt/codebase/dhtmlxcommon.js', + 'static/lib/dhtmlxGantt/codebase/dhtmlxgantt.js', + 'static/src/js/gantt.js' + ], + "css": ['static/lib/dhtmlxGantt/codebase/dhtmlxgantt.css'], + 'active': True } diff --git a/addons/base_gantt/static/src/gantt.js b/addons/base_gantt/static/src/js/gantt.js similarity index 97% rename from addons/base_gantt/static/src/gantt.js rename to addons/base_gantt/static/src/js/gantt.js index 0e65fb48b5b..f8391f2744b 100644 --- a/addons/base_gantt/static/src/gantt.js +++ b/addons/base_gantt/static/src/js/gantt.js @@ -2,9 +2,10 @@ * OpenERP base_gantt *---------------------------------------------------------*/ -openerp.base.gantt = function (openerp) { -openerp.base.views.add('gantt', 'openerp.base.GanttView'); -openerp.base.GanttView = openerp.base.Controller.extend({ +openerp.base_gantt = function (openerp) { +QWeb.add_template('/base_gantt/static/src/xml/base_gantt.xml'); +openerp.base.views.add('gantt', 'openerp.base_gantt.GanttView'); +openerp.base_gantt.GanttView = openerp.base.Controller.extend({ init: function(view_manager, session, element_id, dataset, view_id) { this._super(session, element_id); @@ -216,7 +217,7 @@ openerp.base.GanttView = openerp.base.Controller.extend({ }, function(result) { }) - }, + } }); diff --git a/addons/base_gantt/static/src/xml/base_gantt.xml b/addons/base_gantt/static/src/xml/base_gantt.xml new file mode 100644 index 00000000000..72c14ceb16c --- /dev/null +++ b/addons/base_gantt/static/src/xml/base_gantt.xml @@ -0,0 +1,15 @@ + From 8acaa289a0a8dc20239c78c9bf815c2633e60284 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 14 Apr 2011 15:23:10 +0200 Subject: [PATCH 7/8] [FIX] correctly initialize web_chat addon bzr revid: xmo@openerp.com-20110414132310-qfuewowccf1f2fx9 --- addons/web_chat/__openerp__.py | 12 +++++++++--- addons/web_chat/static/src/js/web_chat.js | 10 ++++++++++ addons/web_chat/static/src/web_chat.html | 24 ----------------------- 3 files changed, 19 insertions(+), 27 deletions(-) create mode 100644 addons/web_chat/static/src/js/web_chat.js delete mode 100644 addons/web_chat/static/src/web_chat.html diff --git a/addons/web_chat/__openerp__.py b/addons/web_chat/__openerp__.py index 9c9ee6f3b2f..e177288953c 100644 --- a/addons/web_chat/__openerp__.py +++ b/addons/web_chat/__openerp__.py @@ -1,8 +1,14 @@ { "name": "Web Chat", "version": "2.0", - "depends": [], - "js": ["static/src/web_chat.js"], + "depends": ['base'], + "js": [ + 'static/lib/AjaxIM/js/jquery.jsonp-1.1.0.js', + 'static/lib/AjaxIM/js/jquery.jstore-all-min.js', + 'static/lib/AjaxIM/js/jquery.md5.js', + 'static/lib/AjaxIM/js/im.js', + 'static/src/js/web_chat.js' + ], "css": [], - 'active': False, + 'active': True, } diff --git a/addons/web_chat/static/src/js/web_chat.js b/addons/web_chat/static/src/js/web_chat.js new file mode 100644 index 00000000000..fce64ee6f78 --- /dev/null +++ b/addons/web_chat/static/src/js/web_chat.js @@ -0,0 +1,10 @@ +openerp.web_chat = function (openerp) { + openerp.web_chat = {}; + openerp.web_chat.im = new AjaxIM({ + storageMethod: 'local', + pollServer: '/web_chat/pollserver', + theme: '/web_chat/static/lib/AjaxIM/themes/default', + flashStorage: '/web_chat/static/lib/AjaxIM/js/jStore.Flash.html' + }); + openerp.web_chat.im.login(); +}; diff --git a/addons/web_chat/static/src/web_chat.html b/addons/web_chat/static/src/web_chat.html deleted file mode 100644 index a1070ab475a..00000000000 --- a/addons/web_chat/static/src/web_chat.html +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - From eac805b553f4898644c439b74fc6d2b6e47add5d Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 14 Apr 2011 15:37:34 +0200 Subject: [PATCH 8/8] [FIX] content-type for chat polling method bzr revid: xmo@openerp.com-20110414133734-y8fv82rhutp0q0nr --- addons/web_chat/controllers/main.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/addons/web_chat/controllers/main.py b/addons/web_chat/controllers/main.py index 9769de33270..5e8d48344f8 100644 --- a/addons/web_chat/controllers/main.py +++ b/addons/web_chat/controllers/main.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import sys, time +import cherrypy import simplejson import random @@ -102,11 +103,6 @@ class PollServer(openerpweb.Controller): @openerpweb.httprequest def poll(self, req, **kw): - - mq = req.applicationsession.setdefault("web_chat", PollServerMessageQueue()) - - # Method: Long Poll - """ --> GET http://im.ajaxim.com/poll?callback=jsonp1302138663582&_1302138663582= <-- 200 OK @@ -129,8 +125,14 @@ class PollServer(openerpweb.Controller): echo '' """ + mq = req.applicationsession.setdefault("web_chat", PollServerMessageQueue()) + + # Method: Long Poll + msg = '[]' + + cherrypy.response.headers['content-type'] = 'application/javascript'; for i in range(5): received_msg = mq.read('Guest1', i) @@ -145,12 +147,6 @@ class PollServer(openerpweb.Controller): @openerpweb.httprequest def send(self, req, **kw): - - to = kw.get('to') - message = kw.get('message') - - mq = req.applicationsession.setdefault("web_chat", PollServerMessageQueue()) - """ --> GET http://im.ajaxim.com/send?callback=jsonp1302139980022&to=Guest130205108745.47&message=test&_1302139980022= callback: jsonp1302139980022 @@ -168,6 +164,12 @@ class PollServer(openerpweb.Controller): """ + to = kw.get('to') + message = kw.get('message') + + mq = req.applicationsession.setdefault("web_chat", PollServerMessageQueue()) + + if not req.applicationsession['current_user']: return dict(r='error', e='no session found') @@ -182,8 +184,6 @@ class PollServer(openerpweb.Controller): @openerpweb.httprequest def status(self, req, **kw): - mq = req.applicationsession.setdefault("web_chat", PollServerMessageQueue()) - """ --> GET status call const Offline = 0; @@ -198,6 +198,8 @@ class PollServer(openerpweb.Controller): return array('r' => 'error', 'e' => 'no session found'); return array('r' => 'error', 'e' => 'status error'); """ + mq = req.applicationsession.setdefault("web_chat", PollServerMessageQueue()) + print "======== chat status ========",kw # mq.write() return {"action": ""}