[IMP] web: remove useless service name
We use the registry keys as name for the services.
This commit is contained in:
@@ -7,7 +7,6 @@ var ServicesMixin = require('web.ServicesMixin');
|
||||
|
||||
var AbstractService = Class.extend(Mixins.EventDispatcherMixin, ServicesMixin, {
|
||||
dependencies: [],
|
||||
name: null,
|
||||
init: function (parent) {
|
||||
Mixins.EventDispatcherMixin.init.call(this, arguments);
|
||||
this.setParent(parent);
|
||||
|
||||
@@ -20,12 +20,18 @@ var ServiceProviderMixin = {
|
||||
|
||||
// add already registered services from the service registry
|
||||
_.each(core.serviceRegistry.map, function (Service, serviceName) {
|
||||
if (serviceName in self.UndeployedServices) {
|
||||
throw new Error('Service "' + serviceName + '" is already loaded.');
|
||||
}
|
||||
self.UndeployedServices[serviceName] = Service;
|
||||
});
|
||||
this._deployServices();
|
||||
|
||||
// listen on newly added services
|
||||
core.serviceRegistry.onAdd(function (serviceName, Service) {
|
||||
if (serviceName in self.services || serviceName in self.UndeployedServices) {
|
||||
throw new Error('Service "' + serviceName + '" is already loaded.');
|
||||
}
|
||||
self.UndeployedServices[serviceName] = Service;
|
||||
self._deployServices();
|
||||
});
|
||||
@@ -42,16 +48,16 @@ var ServiceProviderMixin = {
|
||||
var self = this;
|
||||
var done = false;
|
||||
while (!done) {
|
||||
var Service = _.find(this.UndeployedServices, function (Service) {
|
||||
var serviceName = _.findKey(this.UndeployedServices, function (Service) {
|
||||
// no missing dependency
|
||||
return !_.some(Service.prototype.dependencies, function (depName) {
|
||||
return !self.services[depName];
|
||||
});
|
||||
});
|
||||
if (Service) {
|
||||
var service = new Service(this);
|
||||
this.services[Service.prototype.name] = service;
|
||||
delete this.UndeployedServices[Service.prototype.name];
|
||||
if (serviceName) {
|
||||
var service = new this.UndeployedServices[serviceName](this);
|
||||
this.services[serviceName] = service;
|
||||
delete this.UndeployedServices[serviceName];
|
||||
service.start();
|
||||
} else {
|
||||
done = true;
|
||||
|
||||
@@ -6,7 +6,6 @@ var core = require('web.core');
|
||||
var session = require('web.session');
|
||||
|
||||
var AjaxService = AbstractService.extend({
|
||||
name: 'ajax',
|
||||
rpc: function (route, args, options, target) {
|
||||
return $.Deferred(function (def) {
|
||||
session.rpc(route, args, options).then(function () {
|
||||
|
||||
@@ -10,7 +10,6 @@ var core = require('web.core');
|
||||
var localStorage = require('web.local_storage');
|
||||
|
||||
var LocalStorageService = AbstractStorageService.extend({
|
||||
name: 'local_storage',
|
||||
storage: localStorage,
|
||||
});
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ var id = 0;
|
||||
*/
|
||||
|
||||
var NotificationService = AbstractService.extend({
|
||||
name: 'notification',
|
||||
|
||||
custom_events: {
|
||||
close: '_onCloseNotification',
|
||||
|
||||
@@ -9,7 +9,6 @@ var AbstractService = require('web.AbstractService');
|
||||
var core = require('web.core');
|
||||
|
||||
var ReportService = AbstractService.extend({
|
||||
name: 'report',
|
||||
dependencies: ['ajax'],
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,7 +10,6 @@ var core = require('web.core');
|
||||
var sessionStorage = require('web.sessionStorage');
|
||||
|
||||
var SessionStorageService = AbstractStorageService.extend({
|
||||
name: 'session_storage',
|
||||
storage: sessionStorage,
|
||||
});
|
||||
|
||||
|
||||
@@ -1044,7 +1044,6 @@ QUnit.module('ActionManager', {
|
||||
assert.expect(14);
|
||||
|
||||
var RamStorageService = AbstractStorageService.extend({
|
||||
name: 'session_storage',
|
||||
storage: new RamStorage(),
|
||||
});
|
||||
|
||||
@@ -1052,7 +1051,9 @@ QUnit.module('ActionManager', {
|
||||
actions: this.actions,
|
||||
archs: this.archs,
|
||||
data: this.data,
|
||||
services: [RamStorageService],
|
||||
services: {
|
||||
session_storage: RamStorageService,
|
||||
},
|
||||
mockRPC: function (route, args) {
|
||||
assert.step(args.method || route);
|
||||
return this._super.apply(this, arguments);
|
||||
@@ -1821,7 +1822,9 @@ QUnit.module('ActionManager', {
|
||||
actions: this.actions,
|
||||
archs: this.archs,
|
||||
data: this.data,
|
||||
services: [ReportService],
|
||||
services: {
|
||||
report: ReportService,
|
||||
},
|
||||
mockRPC: function (route, args) {
|
||||
assert.step(args.method || route);
|
||||
if (route === '/report/check_wkhtmltopdf') {
|
||||
@@ -1862,11 +1865,14 @@ QUnit.module('ActionManager', {
|
||||
actions: this.actions,
|
||||
archs: this.archs,
|
||||
data: this.data,
|
||||
services: [ReportService, NotificationService.extend({
|
||||
notify: function (params) {
|
||||
assert.step(params.type || 'notification');
|
||||
}
|
||||
})],
|
||||
services: {
|
||||
report: ReportService,
|
||||
notification: NotificationService.extend({
|
||||
notify: function (params) {
|
||||
assert.step(params.type || 'notification');
|
||||
}
|
||||
}),
|
||||
},
|
||||
mockRPC: function (route, args) {
|
||||
assert.step(args.method || route);
|
||||
if (route === '/report/check_wkhtmltopdf') {
|
||||
@@ -1916,11 +1922,14 @@ QUnit.module('ActionManager', {
|
||||
actions: this.actions,
|
||||
archs: this.archs,
|
||||
data: this.data,
|
||||
services: [ReportService, NotificationService.extend({
|
||||
notify: function (params) {
|
||||
assert.step(params.type || 'notification');
|
||||
}
|
||||
})],
|
||||
services: {
|
||||
report: ReportService,
|
||||
notification: NotificationService.extend({
|
||||
notify: function (params) {
|
||||
assert.step(params.type || 'notification');
|
||||
}
|
||||
})
|
||||
},
|
||||
mockRPC: function (route, args) {
|
||||
assert.step(args.method || route);
|
||||
if (route === '/report/check_wkhtmltopdf') {
|
||||
@@ -2979,12 +2988,14 @@ QUnit.module('ActionManager', {
|
||||
actions: this.actions,
|
||||
archs: this.archs,
|
||||
data: this.data,
|
||||
services: [SessionStorageService.extend({
|
||||
setItem: function (key, value) {
|
||||
assert.strictEqual(value, JSON.stringify(expectedAction),
|
||||
"should store the executed action in the sessionStorage");
|
||||
},
|
||||
})],
|
||||
services: {
|
||||
session_storage: SessionStorageService.extend({
|
||||
setItem: function (key, value) {
|
||||
assert.strictEqual(value, JSON.stringify(expectedAction),
|
||||
"should store the executed action in the sessionStorage");
|
||||
},
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
actionManager.doAction(3);
|
||||
@@ -3010,14 +3021,16 @@ QUnit.module('ActionManager', {
|
||||
actions: this.actions,
|
||||
archs: this.archs,
|
||||
data: this.data,
|
||||
services: [SessionStorageService.extend({
|
||||
setItem: function (key, value) {
|
||||
if (checkSessionStorage) {
|
||||
assert.strictEqual(value, JSON.stringify(expectedAction),
|
||||
"should correctly store the executed action in the sessionStorage");
|
||||
}
|
||||
},
|
||||
})],
|
||||
services: {
|
||||
session_storage: SessionStorageService.extend({
|
||||
setItem: function (key, value) {
|
||||
if (checkSessionStorage) {
|
||||
assert.strictEqual(value, JSON.stringify(expectedAction),
|
||||
"should correctly store the executed action in the sessionStorage");
|
||||
}
|
||||
},
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
// execute an action and open a record in form view
|
||||
|
||||
@@ -427,15 +427,15 @@ function addMockEnvironment(widget, params) {
|
||||
// Deploy services
|
||||
var done = false;
|
||||
while (!done) {
|
||||
var index = _.findIndex(params.services, function (Service) {
|
||||
var serviceName = _.findKey(params.services, function (Service) {
|
||||
return !_.some(Service.prototype.dependencies, function (depName) {
|
||||
return !_.has(services, depName);
|
||||
});
|
||||
});
|
||||
if (index !== -1) {
|
||||
var Service = params.services.splice(index, 1)[0];
|
||||
services[Service.prototype.name] = new Service(widget);
|
||||
services[Service.prototype.name].start();
|
||||
if (serviceName) {
|
||||
var service = services[serviceName] = new params.services[serviceName](widget);
|
||||
delete params.services[serviceName];
|
||||
service.start();
|
||||
} else {
|
||||
done = true;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,9 @@ QUnit.module('Services', {
|
||||
},
|
||||
},
|
||||
model: 'fake_model',
|
||||
services: [NotificationService],
|
||||
services: {
|
||||
notification: NotificationService,
|
||||
},
|
||||
};
|
||||
},
|
||||
afterEach: function () {
|
||||
|
||||
@@ -2850,17 +2850,19 @@ QUnit.module('Views', {
|
||||
arch: '<form string="Partners">' +
|
||||
'<group><field name="foo"/></group>' +
|
||||
'</form>',
|
||||
services: [NotificationService.extend({
|
||||
notify: function (params) {
|
||||
if (params.type !== 'warning') {
|
||||
return;
|
||||
services: {
|
||||
notification: NotificationService.extend({
|
||||
notify: function (params) {
|
||||
if (params.type !== 'warning') {
|
||||
return;
|
||||
}
|
||||
assert.strictEqual(params.title, 'The following fields are invalid:',
|
||||
"should have a warning with correct title");
|
||||
assert.strictEqual(params.message, '<ul><li>Foo</li></ul>',
|
||||
"should have a warning with correct message");
|
||||
}
|
||||
assert.strictEqual(params.title, 'The following fields are invalid:',
|
||||
"should have a warning with correct title");
|
||||
assert.strictEqual(params.message, '<ul><li>Foo</li></ul>',
|
||||
"should have a warning with correct message");
|
||||
}
|
||||
})],
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
form.$buttons.find('.o_form_button_save').click();
|
||||
@@ -4934,11 +4936,13 @@ QUnit.module('Views', {
|
||||
}
|
||||
return result;
|
||||
},
|
||||
services: [NotificationService.extend({
|
||||
notify: function (params) {
|
||||
assert.step(params.type);
|
||||
}
|
||||
})],
|
||||
services: {
|
||||
notification: NotificationService.extend({
|
||||
notify: function (params) {
|
||||
assert.step(params.type);
|
||||
}
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
form.$buttons.find('.o_form_button_edit').click();
|
||||
|
||||
@@ -2154,13 +2154,15 @@ QUnit.module('Views', {
|
||||
'<field name="foo" required="1"/>' +
|
||||
'<field name="bar"/>' +
|
||||
'</tree>',
|
||||
services: [NotificationService.extend({
|
||||
notify: function (params) {
|
||||
if (params.type === 'warning') {
|
||||
warnings++;
|
||||
services: {
|
||||
notification: NotificationService.extend({
|
||||
notify: function (params) {
|
||||
if (params.type === 'warning') {
|
||||
warnings++;
|
||||
}
|
||||
}
|
||||
}
|
||||
})],
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
// Start first line edition
|
||||
|
||||
Reference in New Issue
Block a user