|
@@ -0,0 +1,55 @@
|
|
|
+openerp.printers_manager = function(instance, local) {
|
|
|
+
|
|
|
+ local.TestWidget = instance.Widget.extend({
|
|
|
+ template: 'test_widget_tmpl',
|
|
|
+ events: {
|
|
|
+ 'click input': 'send_data'
|
|
|
+ },
|
|
|
+ start() {
|
|
|
+ this.socket = new WebSocket('ws://127.0.0.1:8701')
|
|
|
+ this.on('change:printers', this, this.populate_selector)
|
|
|
+ var self = this;
|
|
|
+
|
|
|
+ this.socket.onopen = function (e) {
|
|
|
+ self.socket.send(JSON.stringify({
|
|
|
+ 'action': 'list'
|
|
|
+ }))
|
|
|
+ }
|
|
|
+
|
|
|
+ this.socket.onmessage = function (e) {
|
|
|
+ self.set('printers', JSON.parse(e.data));
|
|
|
+ }
|
|
|
+ },
|
|
|
+ populate_selector: function () {
|
|
|
+ var printers = this.get('printers').printers;
|
|
|
+
|
|
|
+ if (!printers) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (var i = 0; i < printers.length; i++) {
|
|
|
+ this.$el.find('select').append('<option>' + printers[i] + '</option>');
|
|
|
+ }
|
|
|
+ },
|
|
|
+ send_data: function (e) {
|
|
|
+ e.preventDefault();
|
|
|
+
|
|
|
+ var serializeData = $(e.target).closest('form').serialize();
|
|
|
+ var fields = serializeData.split(/\&/)
|
|
|
+ var obj = {
|
|
|
+ action: 'print'
|
|
|
+ }
|
|
|
+
|
|
|
+ for (var i = 0; i < fields.length; i++) {
|
|
|
+ var values = fields[i].split(/\=/);
|
|
|
+ obj[values[0]] = values[1].replace(/\+/g, ' ').replace(/%0D%0A/g, '\n');
|
|
|
+ }
|
|
|
+
|
|
|
+ this.socket.send(JSON.stringify(obj));
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ instance.web.client_actions.add('printers_manager.printers_view', 'instance.printers_manager.TestWidget');
|
|
|
+}
|