Skip to content
Browse files

Major surgery, lots of blood. baseURL control is now responsability o…

…f Directory. Renderers should overrid paint method instead of draw. Components use a service directory instead of document.page.getService...
  • Loading branch information...
1 parent 2010f91 commit 3de7a1368c745e5a91043e082feea69151d2eadb @eamodeorubio eamodeorubio committed
View
2 examples/showCase.html
@@ -16,6 +16,8 @@
<script src="../src/Cuore.Component.js" type="text/javascript"></script>
<script src="../src/Cuore.Renderer.js" type="text/javascript"></script>
<script src="../src/Cuore.Handler.js" type="text/javascript"></script>
+ <script src="../src/Cuore.Directory.js" type="text/javascript"></script>
+ <script src="../src/Cuore.Registry.js" type="text/javascript"></script>
<script src="../src/Cuore.Service.js" type="text/javascript"></script>
<script src="../src/Cuore.Journey.js" type="text/javascript"></script>
View
36 spec/Components/Cuore.Components.Button.Spec.js
@@ -49,21 +49,12 @@ describe("Button", function () {
it("default name is 'aButton' and service is defaulted to 'BUTTON'", function () {
var aButton = new CUORE.Components.Button();
-
- var calledProcedure = null;
- var aService = {};
- aService.execute = function (procedure, data) {
- calledProcedure = procedure;
- };
- var calledService = undefined;
- aButton.getService = function () {
- calledService = this.service;
- return aService;
- };
+ var aDirectory = CUORE.Mocks.Directory();
+ aButton.setDirectory(aDirectory);
aButton.click();
- expect(calledProcedure).toEqual("aButton");
- expect(calledService).toEqual("BUTTON");
+
+ expect(aDirectory.execute).toHaveBeenCalledWith("BUTTON", 'aButton', null);
});
it("generates an anchor in DOM with a span for css replacement when it is drawn", function () {
@@ -128,15 +119,13 @@ describe("Button", function () {
var buttonName = "buttonName";
var aButton = new CUORE.Components.Button(buttonName, "CanonicalKey");
var someData="Some Data";
- var myMockedService={};
- myMockedService.execute=function(){};
- spyOn(myMockedService,'execute');
aButton.setData(someData);
- aButton.getService=function() {
- return myMockedService;
- }
- aButton.click();
- expect(myMockedService.execute).toHaveBeenCalledWith(buttonName,someData);
+ var aDirectory = CUORE.Mocks.Directory();
+ aButton.setDirectory(aDirectory);
+
+ aButton.click();
+
+ expect(aDirectory.execute).toHaveBeenCalledWith("BUTTON", buttonName, someData);
});
it("default event is stopped even when disabled", function () {
@@ -225,10 +214,12 @@ describe("Button", function () {
expect(DOMButton).toBeFalsy();
});
- it("requests a label when it is drawn", function () {
+ // Not necessary anymore!
+ xit("requests a label when it is drawn", function () {
var container = createTestContainer();
var buttonName = "buttonName";
var aButton = new CUORE.Components.Button(buttonName, "CanonicalKey");
+
aButton.setContainer(container.id);
var getLabelCalled = false;
@@ -240,7 +231,6 @@ describe("Button", function () {
aButton.draw();
expect(getLabelCalled).toBeTruthy();
-
});
var createTestContainer = function() {
View
31 spec/Components/Cuore.Components.Nestable.Spec.js
@@ -19,6 +19,37 @@ describe("NestableComponent", function () {
expect(aComponent.hosted()).toContain(anyComponent);
});
+ it("when a component is hosted, is configured with the directory", function () {
+ var anyComponent = CUORE.Mocks.Component('any component');
+ var aDirectory=CUORE.Mocks.Directory();
+ var aComponent = new CUORE.Components.Nestable();
+ aComponent.setDirectory(aDirectory);
+
+ aComponent.host(anyComponent);
+
+ expect(anyComponent.setDirectory).toHaveBeenCalledWith(aDirectory);
+ });
+
+ it("when a component is hosted, it won't replace the contents", function () {
+ var anyComponent = CUORE.Mocks.Component('any component');
+ var aComponent = new CUORE.Components.Nestable();
+
+ aComponent.host(anyComponent);
+
+ expect(anyComponent.dontReplace).toHaveBeenCalled();
+ });
+
+ it("when the directory is changed, the hosted components are reconfigured with the new one", function () {
+ var aDirectory=CUORE.Mocks.Directory();
+ var anyComponent = CUORE.Mocks.Component('any component');
+ var aComponent = new CUORE.Components.Nestable();
+ aComponent.host(anyComponent);
+
+ aComponent.setDirectory(aDirectory);
+
+ expect(anyComponent.setDirectory).toHaveBeenCalledWith(aDirectory);
+ });
+
it("knows events managed by nested Components", function () {
var anyComponent = new CUORE.Component();
var aHandler = {};
View
58 spec/Components/Cuore.Components.SwitchButton.Spec.js
@@ -1,5 +1,5 @@
describe("SwitchButton", function () {
-
+
var xhr;
beforeEach(function(){
@@ -21,7 +21,7 @@ describe("SwitchButton", function () {
xhr.restore();
});
-
+
it("inherits Component and Button", function () {
var keyActive = "testKeyActive";
@@ -39,50 +39,37 @@ describe("SwitchButton", function () {
expect(aButton.getInactiveLabel()).toEqual("CLICK!");
});
- it("should ignore undefined keys when getLabel called", function () {
- var aButton = new CUORE.Components.SwitchButton();
- var calledGetLabelService = false;
- aButton.getLabelService = function () {
- calledGetLabelService = true;
- };
- aButton.getLabel(null);
- aButton.getLabel(undefined);
- expect(calledGetLabelService).toBeFalsy();
- });
-
it("should request active and inactive key when drawn", function () {
var container = createTestContainer();
var keyActive = "testKeyActive";
var keyInactive = "testKeyInactive";
var aButton = new CUORE.Components.SwitchButton("buttonName", keyActive, keyInactive);
+ var aDirectory = CUORE.Mocks.Directory();
+ aButton.setDirectory(aDirectory);
aButton.setContainer(container.id);
- var labelsRequested = [];
- aButton.getLabel = function (aLabel) {
- labelsRequested.push(aLabel);
- };
-
aButton.draw();
expect(aButton.getActiveKey()).toEqual(keyActive);
expect(aButton.getInactiveKey()).toEqual(keyInactive);
- expect(labelsRequested).toContain(keyActive);
- expect(labelsRequested).toContain(keyInactive);
+ expect(aDirectory.execute).toHaveBeenCalledWith("LABELS", 'getLabel', {key:keyActive}, true);
+ expect(aDirectory.execute).toHaveBeenCalledWith("LABELS", 'getLabel', {key:keyInactive}, true);
});
it("should switches state, label and cssclass when clicked", function () {
var container = createTestContainer();
var aButton = new CUORE.Components.SwitchButton("buttonName", "testKeyActive", "testKeyInactive");
+ aButton.setDirectory(CUORE.Mocks.Directory());
aButton.setContainer(container.id);
var activeLabel = "active";
var inactiveLabel = "inactive";
var activeMessage = new CUORE.Message();
- activeMessage.putOnAnswer("text",activeLabel);
-
+ activeMessage.putOnAnswer("text",activeLabel);
+
var inactiveMessage = new CUORE.Message();
- inactiveMessage.putOnAnswer("text",inactiveLabel);
+ inactiveMessage.putOnAnswer("text",inactiveLabel);
aButton.setActiveLabel(activeMessage);
aButton.setInactiveLabel(inactiveMessage);
@@ -109,25 +96,26 @@ describe("SwitchButton", function () {
});
it("should emit event when clicked", function () {
- var aButton = new CUORE.Components.SwitchButton("buttonName", "testKeyActive", "testKeyInactive");
-
- var aService = {};
- aService.execute = function() {};
- spyOn(aService, 'execute');
-
- aButton.getService = function () {
- return aService;
- };
+ var buttonName="buttonName";
+ var someData="someData";
+ var aDirectory=CUORE.Mocks.Directory();
+ var aButton = new CUORE.Components.SwitchButton(buttonName, "testKeyActive", "testKeyInactive");
+ aButton.setDirectory(aDirectory);
+ aButton.setData(someData);
aButton.click();
- expect(aService.execute).toHaveBeenCalled();
+ expect(aDirectory.execute).toHaveBeenCalledWith("BUTTON", buttonName, someData);
+ });
- aService.execute.reset();
+ it("should not emit event when clicked and false is passed as argument", function () {
+ var aDirectory=CUORE.Mocks.Directory();
+ var aButton = new CUORE.Components.SwitchButton("buttonName", "testKeyActive", "testKeyInactive");
+ aButton.setDirectory(CUORE.Mocks.Directory());
aButton.click(false);
- expect(aService.execute).not.toHaveBeenCalled();
+ expect(aDirectory.execute).not.toHaveBeenCalled();
});
it("should get labelHandler when initialized", function () {
View
27 spec/Cuore.Component.Spec.js
@@ -22,7 +22,7 @@ describe("Component", function() {
xhr.restore();
});
- it("execution context initialization needs both service and procedure", function() {
+ xit("execution context initialization needs both service and procedure", function() {
var aService = "IAmaService";
var aProcedure = "IAmaProcedure";
var defaultService = "NULL";
@@ -55,7 +55,7 @@ describe("Component", function() {
aComponent.setRenderer(aRenderer);
- aComponent.render();
+ aComponent.draw();
expect(aRenderer.render).toHaveBeenCalled();
});
@@ -86,11 +86,12 @@ describe("Component", function() {
};
var aComponent = new CUORE.Component();
- aComponent.eventDispatch(eventName, params);
- expect(true).toBeTruthy();
+
+ expect(function() {
+ aComponent.eventDispatch(eventName, params);
+ }).not.toThrow();
});
-
it("knows events managed by handlers", function() {
var eventName = "anEvent";
var anotherEvent = "anotherEvent";
@@ -190,7 +191,8 @@ describe("Component", function() {
expect(element.className).toBe("innerComponentDiv");
});
- it("has I18NKey label getter & setter", function() {
+ // Moved to ComponentSurgery.Spec
+ xit("has I18NKey label getter & setter", function() {
var aI18Nkey = "CanonicalKey";
var aComponent = new CUORE.Component();
@@ -198,8 +200,8 @@ describe("Component", function() {
expect(aComponent.getI18NKey(aI18Nkey)).toEqual(aI18Nkey);
});
-
- it("requests their label when it is drawn", function() {
+ // We think it has no sense
+ xit("requests their label when it is drawn", function() {
var aService = {};
var receivedParams = undefined;
aService.execute = function(procedure, params, flag) {
@@ -231,7 +233,8 @@ describe("Component", function() {
expect(calledService).toEqual(LABELSERVICENAME);
});
- it("has a Handler for its label when i18nkey setted", function() {
+ // Moved to ComponentSurgery.Spec
+ xit("has a Handler for its label when i18nkey setted", function() {
var eventName = "LABELS_getLabel_EXECUTED_CanonicalKey";
var aComponent = new CUORE.Component();
aComponent.setI18NKey("CanonicalKey");
@@ -240,7 +243,7 @@ describe("Component", function() {
expect(events).toContain(eventName);
});
- it("is suscribed to the bus on I18NKey set", function() {
+ xit("is suscribed to the bus on I18NKey set", function() {
var receivedSubscriber = undefined;
var receivedEvent = undefined;
CUORE.Bus.reset();
@@ -262,7 +265,7 @@ describe("Component", function() {
});
- it("does not request its label when drawn if it hasn't a I18Key", function() {
+ xit("does not request its label when drawn if it hasn't a I18Key", function() {
var aService = {};
var receivedParams = undefined;
aService.execute = function(procedure, params, flag) {
@@ -288,7 +291,7 @@ describe("Component", function() {
});
- it("does not request its label when asked (getLabel) if it hasn't a I18Key", function() {
+ xit("does not request its label when asked (getLabel) if it hasn't a I18Key", function() {
var aService = {};
var receivedParams = undefined;
aService.execute = function(procedure, params, flag) {
View
135 spec/Cuore.ComponentSurgery.Spec.js
@@ -14,16 +14,135 @@ describe("A component", function() {
expect(aComponent.doYouReplace()).toBeFalsy();
});
- it("can execute a service through the directory", function() {
- var aDirectory = CUORE.Mocks.Directory();
- aComponent.setDirectory(aDirectory);
+ describe("given a service directory is set", function() {
+ var aDirectory;
+ beforeEach(function() {
+ aDirectory = CUORE.Mocks.Directory();
+ aComponent.setDirectory(aDirectory);
+ });
- var theServiceName = "serviceName";
- var theProcedureName = "procedureName";
- var params = "these are the mock params";
+ it("should ignore undefined keys when getLabel called", function () {
+ aComponent.requestLabelText(null);
+ aComponent.requestLabelText(undefined);
- aComponent.execute(theServiceName, theProcedureName, params, true);
+ expect(aDirectory.execute).not.toHaveBeenCalled();
+ });
- expect(aDirectory.execute).toHaveBeenCalledWith(theServiceName, theProcedureName, params, true);
+ it("can execute a service through the directory", function() {
+ var theServiceName = "serviceName";
+ var theProcedureName = "procedureName";
+ var params = "these are the mock params";
+
+ aComponent.execute(theServiceName, theProcedureName, params, true);
+
+ expect(aDirectory.execute).toHaveBeenCalledWith(theServiceName, theProcedureName, params, true);
+ });
+
+ describe("when i18n label is changed", function() {
+ it("label service is used to fetch the label text", function() {
+ var labelKey="label.key";
+
+ aComponent.setI18NKey(labelKey);
+
+ expect(aDirectory.execute).toHaveBeenCalledWith("LABELS", 'getLabel', {key:labelKey}, true);
+ });
+
+ it("and the key is empty, label service won't be used to fetch the label text", function() {
+ aComponent.setI18NKey(null);
+
+ expect(aDirectory.execute).not.toHaveBeenCalled();
+ });
+
+ it("the component's text is set to the label key while the label service has not yet replied", function() {
+ var labelKey="label.key";
+
+ aComponent.setI18NKey(labelKey);
+
+ expect(aComponent.getText()).toContain(labelKey);
+ });
+
+ it("a handler exists to receive the label value", function() {
+ var labelKey="label.key";
+
+ aComponent.setI18NKey(labelKey);
+
+ expect(aComponent.getManagedEvents()).toContain('LABELS_getLabel_EXECUTED_'+labelKey);
+ });
+
+ it("when dispatch is called, the handler registered to receive the label value changes the component's text", function() {
+ var labelKey="label.key";
+ var labelText='label text';
+ var message= CUORE.Mocks.mock("label message", ['getFromAnswer']);
+ message.getFromAnswer.andReturn(labelText);
+ aComponent.setI18NKey(labelKey);
+
+ aComponent.eventDispatch('LABELS_getLabel_EXECUTED_'+labelKey, message);
+
+ expect(message.getFromAnswer).toHaveBeenCalledWith('text');
+ expect(aComponent.getText()).toEqual(labelText);
+ });
+ });
+ });
+
+ describe("given the directory has not yet been set", function() {
+ it("can execute a service through the directory", function() {
+ var theServiceName = "serviceName";
+ var theProcedureName = "procedureName";
+ var params = "these are the mock params";
+
+ expect(function() {
+ aComponent.execute(theServiceName, theProcedureName, params, true);
+ }).toThrow("Cannot call service. A service directory is not configured");
+ });
+
+ describe("when i18n label is changed", function() {
+ it("and the key is empty it won't change the text", function() {
+ var labelKey="label.key";
+ aComponent.setI18NKey(labelKey);
+
+ aComponent.setI18NKey(null);
+
+ expect(aComponent.getText()).toContain(labelKey);
+ });
+
+ it("the component's text is set to the label key", function() {
+ var labelKey="label.key";
+
+ aComponent.setI18NKey(labelKey);
+
+ expect(aComponent.getText()).toContain(labelKey);
+ });
+
+ it("a handler exists to receive the label value", function() {
+ var labelKey="label.key";
+
+ aComponent.setI18NKey(labelKey);
+
+ expect(aComponent.getManagedEvents()).toContain('LABELS_getLabel_EXECUTED_'+labelKey);
+ });
+
+ it("when dispatch is called, the handler registered to receive the label value changes the component's text", function() {
+ var labelKey="label.key";
+ var labelText='label text';
+ var message= CUORE.Mocks.mock("label message", ['getFromAnswer']);
+ message.getFromAnswer.andReturn(labelText);
+ aComponent.setI18NKey(labelKey);
+
+ aComponent.eventDispatch('LABELS_getLabel_EXECUTED_'+labelKey, message);
+
+ expect(message.getFromAnswer).toHaveBeenCalledWith('text');
+ expect(aComponent.getText()).toEqual(labelText);
+ });
+
+ it("a label service is used to fetch the label text but only when the directory is configured", function() {
+ var labelKey="label.key";
+ var aDirectory=CUORE.Mocks.Directory();
+
+ aComponent.setI18NKey(labelKey);
+ aComponent.setDirectory(aDirectory);
+
+ expect(aDirectory.execute).toHaveBeenCalledWith("LABELS", 'getLabel', {key:labelKey}, true);
+ });
+ });
});
});
View
26 spec/Cuore.Directory.Spec.js
@@ -6,7 +6,7 @@ describe("A Directory", function () {
return service;
};
- var aDirectory;
+ var aDirectory, defaultBaseUrl="base URL";
beforeEach(function() {
this.addMatchers({
@@ -20,15 +20,24 @@ describe("A Directory", function () {
});
aDirectory = new CUORE.Directory();
+ aDirectory.setBaseURL(defaultBaseUrl);
});
it("has a Label service built-in", function () {
expect(aDirectory.getService('LABELS')).toBeInstanceOf(CUORE.Services.Label);
});
+ it("has a Label service built-in with a proper base url", function () {
+ expect(aDirectory.getService('LABELS').getBaseURL()).toEqual(defaultBaseUrl);
+ });
+
it("has a Button service built-in", function () {
expect(aDirectory.getService('BUTTON')).toBeInstanceOf(CUORE.Services.Button);
});
+
+ it("has a Button service built-in with a proper base url", function () {
+ expect(aDirectory.getService('BUTTON').getBaseURL()).toEqual(defaultBaseUrl);
+ });
describe("with a service called 'TAL'", function() {
var tal="TAL";
@@ -43,11 +52,24 @@ describe("A Directory", function () {
it("the service 'TAL' will be asked for its name", function () {
expect(talService.getName).toHaveBeenCalled();
});
+
+ it("the service 'TAL' will be configured with a baseURL", function () {
+ expect(talService.setBaseURL).toHaveBeenCalledWith(defaultBaseUrl);
+ });
it("and the listing will contain 'TAL'", function () {
expect(aDirectory.list()).toContain(tal);
});
-
+
+
+ it("when baseURL is changed, all the services are reconfigured", function() {
+ var anotherURL="another base URL";
+
+ aDirectory.setBaseURL(anotherURL);
+
+ expect(talService.setBaseURL).toHaveBeenCalledWith(anotherURL);
+ });
+
it("when service 'PASCUAL' is added, then the listing will contain 'TAL' and 'PASCUAL'", function () {
var pascual="PASCUAL";
View
2 spec/Cuore.Mocks.js
@@ -15,7 +15,7 @@ CUORE.Mocks = {
},
Directory: function() {
- return CUORE.Mocks.mock('directory', ['add', 'list', 'execute', 'getService']);
+ return CUORE.Mocks.mock('directory', ['add', 'list', 'execute', 'getService', 'setBaseURL']);
},
Service: function() {
View
33 spec/Cuore.Page.Spec.js
@@ -44,34 +44,21 @@ describe("Page", function () {
expect(aService).toEqual(expectedService);
});
- it("by default has an empty baseUrl", function () {
- expect(aPage.getBaseURL()).toEqual("");
- });
-
- it("allows baseUrl initialization using the constructor", function () {
- aPage = new CUORE.Page("A Base URL");
+ it("when baseURL is configured, it informs the directory", function () {
+ var baseURL="A Base URL";
+ aPage = new CUORE.Page(baseURL);
+ aPage.setDirectory(directory);
- expect(aPage.getBaseURL()).toEqual("A Base URL");
+ expect(directory.setBaseURL).toHaveBeenCalledWith(baseURL);
});
- describe("when a service is added", function() {
- var aService, aBaseURL="a base URL";
-
- beforeEach(function() {
- aService = CUORE.Mocks.Service();
- aPage = new CUORE.Page(aBaseURL);
- aPage.setDirectory(directory);
-
- aPage.addService(aService);
- });
+ it("when a service is added then adds the service to the directory", function() {
+ var aService = CUORE.Mocks.Service();
+ aPage.setDirectory(directory);
- it("it sets the baseURL to the service", function() {
- expect(aService.setBaseURL).toHaveBeenCalledWith(aBaseURL);
- });
+ aPage.addService(aService);
- it("it adds the service to the directory", function() {
- expect(directory.add).toHaveBeenCalledWith(aService);
- });
+ expect(directory.add).toHaveBeenCalledWith(aService);
});
describe("when a component is added", function() {
View
8 src/Components/Cuore.Components.Button.js
@@ -13,12 +13,10 @@ CUORE.Components.Button = CUORE.Class(CUORE.Component, {
},
click: function() {
- var service = this.getService();
- service && service.execute(this.buttonName, this.data);
+ if(this.service)
+ this.services.execute(this.service, this.buttonName, this.data);
},
-
-
getButtonName: function() {
return this.buttonName;
},
@@ -26,6 +24,4 @@ CUORE.Components.Button = CUORE.Class(CUORE.Component, {
setData: function(data) {
this.data = data;
}
-
-
});
View
11 src/Components/Cuore.Components.Nestable.js
@@ -7,16 +7,25 @@ CUORE.Components.Nestable = CUORE.Class(CUORE.Component, {
},
host: function (anyComponent) {
+ anyComponent.setDirectory(this.services);
+ anyComponent.dontReplace();
this.hostedComponents.push(anyComponent);
},
+ setDirectory: function(aDirectory) {
+ CUORE.Components.Nestable.super.setDirectory.call(this, aDirectory);
+
+ for (var i = 0, len = this.hostedComponents.length; i < len; i++)
+ this.hostedComponents[i].setDirectory(aDirectory);
+ },
+
hosted: function (anyComponent) {
return this.hostedComponents;
},
getManagedEvents: function () {
var result = CUORE.Components.Nestable.super.getManagedEvents.call(this);
-
+
for (var i = 0, len = this.hostedComponents.length; i < len; i++) {
result.push.apply(result, this.hostedComponents[i].getManagedEvents());
}
View
17 src/Components/Cuore.Components.SwitchButton.js
@@ -19,9 +19,9 @@ CUORE.Components.SwitchButton = CUORE.Class(CUORE.Components.Button, {
},
draw: function () {
- this.getLabel(this.activeKey);
- this.getLabel(this.inactiveKey);
- this.render();
+ this.requestLabelText(this.activeKey);
+ this.requestLabelText(this.inactiveKey);
+ CUORE.Components.SwitchButton.super.draw.call(this);
},
click: function (executeParent) {
@@ -43,17 +43,6 @@ CUORE.Components.SwitchButton = CUORE.Class(CUORE.Components.Button, {
return this.active;
},
- getLabel: function (key) {
- if (!key) return;
-
- var labelService = this.getLabelService();
- var params = { 'key': key };
-
- if (labelService) {
- labelService.execute('getLabel', params, true);
- }
- },
-
setActiveLabel: function (message) {
this.activeLabel = message.getFromAnswer('text');
this.updateRender();
View
50 src/Cuore.Component.js
@@ -15,6 +15,7 @@ CUORE.Component = CUORE.Class(null, {
setDirectory: function(directory) {
this.services = directory;
+ this._requestLabelText();
},
initializeExecutionContext: function(service, procedure) {
@@ -29,15 +30,10 @@ CUORE.Component = CUORE.Class(null, {
},
dontReplace: function() {
- this.replaces = false;
+ this.replaces = false;
},
draw: function() {
- this.render();
- this.getLabel();
- },
-
- render: function() {
this.renderer.render(this);
},
@@ -49,12 +45,10 @@ CUORE.Component = CUORE.Class(null, {
this.renderer.erase();
CUORE.Bus.unsubscribe(this, this.getManagedEvents());
},
-
- getLabelService: function() {
- return this.getService('LABELS');
- },
execute: function(theService, theProcedure, params, asynchronous) {
+ if(!this.services)
+ throw new Error("Cannot call service. A service directory is not configured");
this.services.execute(theService, theProcedure, params, asynchronous);
},
@@ -101,18 +95,6 @@ CUORE.Component = CUORE.Class(null, {
return this.renderer.getContainer();
},
- getService: function(aService) {
- var theService = aService || this.service;
- return (document.page.getService(theService) || null);
- },
-
- getLabel: function() {
- if (!this.I18NKey || !this.getLabelService()) return;
-
- var params = { key: this.I18NKey };
- this.getLabelService().execute('getLabel', params, true);
- },
-
getUniqueID: function() {
return this.renderer.innerDivName(this.name);
},
@@ -136,9 +118,27 @@ CUORE.Component = CUORE.Class(null, {
if (!key) return;
this.I18NKey = key;
- this.addHandler('LABELS_getLabel_EXECUTED_' + key, new CUORE.Handlers.setText());
- CUORE.Bus.subscribe(this, 'LABELS_getLabel_EXECUTED_' + key);
- this.getLabel();
+ this.setText(this.I18NKey);
+
+ this._requestLabelText();
+ },
+
+ requestLabelText:function(key) {
+ if(!key)
+ return;
+
+ if(this.services)
+ this.services.execute("LABELS", 'getLabel', {key: key}, true);
+ },
+
+ _requestLabelText:function() {
+ if(!this.I18NKey)
+ return;
+
+ this.addHandler('LABELS_getLabel_EXECUTED_' + this.I18NKey, new CUORE.Handlers.setText());
+ CUORE.Bus.subscribe(this, 'LABELS_getLabel_EXECUTED_' + this.I18NKey);
+
+ this.requestLabelText(this.I18NKey);
},
getI18NKey: function() {
View
23 src/Cuore.Directory.js
@@ -3,28 +3,45 @@ CUORE.Directory = CUORE.Class(null, {
init: function(baseURL) {
this.listing=[];
this.services={};
+
+ this.setBaseURL(baseURL);
this._addBuiltinServices();
},
add: function (aService){
var serviceName=aService.getName();
this.listing.push(serviceName);
+ aService.setBaseURL(this.baseURL);
this.services[serviceName]=aService;
},
- list: function(){return this.listing;},
+ list: function(){
+ return this.listing;
+ },
execute: function(serviceName, procedureName, params, asynchronous){
this.getService(serviceName).execute(procedureName, params, asynchronous);
},
getService:function(serviceName) {
- var service=this.services[serviceName];
+ var service=this._findService(serviceName);
if(!service)
service=new CUORE.Services.Null();
return service;
},
-
+
+ setBaseURL: function(baseURL) {
+ this.baseURL = baseURL || '';
+ var serviceNames=this.list();
+ var numberOfServices=serviceNames.length;
+ for(var i=0;i<numberOfServices;i++)
+ this._findService(serviceNames[i]).setBaseURL(this.baseURL);
+ },
+
+ _findService: function(serviceName) {
+ return this.services[serviceName];
+ },
+
_addBuiltinServices:function (){
this.add(new CUORE.Services.Label());
this.add(new CUORE.Services.Button());
View
14 src/Cuore.Page.js
@@ -1,10 +1,10 @@
CUORE.Page = CUORE.Class(null, {
init: function(baseURL) {
- this.baseURL = baseURL || '';
+ this.baseURL=baseURL;
this.components = new CUORE.Registry();
this.services = new CUORE.Directory();
- document.page = this;
+ this.services.setBaseURL(baseURL);
this.setUp();
},
@@ -12,8 +12,13 @@ CUORE.Page = CUORE.Class(null, {
this.components = registry;
},
+ _getBaseURL:function() {
+ return this.baseURL;
+ },
+
setDirectory:function(directory) {
this.services = directory;
+ this.services.setBaseURL(this._getBaseURL());
},
initializeServices: function() {},
@@ -25,7 +30,6 @@ CUORE.Page = CUORE.Class(null, {
},
addService: function(service) {
- service.setBaseURL(this.getBaseURL());
this.services.add(service);
},
@@ -52,10 +56,6 @@ CUORE.Page = CUORE.Class(null, {
component.draw();
});
},
-
- getBaseURL: function() {
- return this.baseURL;
- },
_subcribeComponentEvents: function(component) {
var events = component.getManagedEvents();
View
8 src/Cuore.Renderer.js
@@ -69,9 +69,13 @@ CUORE.Renderer = CUORE.Class(null, {
if (component.doYouReplace()){
this.container.innerHTML='';
}
-
+
+ this.paint(component);
+ },
+
+ paint: function(component) {
var divID = this.innerDivName(component.getName());
-
+
this.panel = CUORE.Dom.createElement('div', {
id: divID
}, this.container);
View
2 src/Renderers/Cuore.Renderers.Button.js
@@ -6,7 +6,7 @@ CUORE.Renderers.Button = CUORE.Class(CUORE.Renderer, {
this.DOMClass = 'button';
},
- draw: function(component) {
+ paint: function(component) {
this.panel = CUORE.Dom.createElement('a', {
id: this.innerDivName(component.getName()),
href: '#'
View
3 src/Renderers/Cuore.Renderers.Input.js
@@ -1,6 +1,6 @@
CUORE.Renderers.Input = CUORE.Class(CUORE.Renderer, {
- draw: function (component) {
+ paint: function (component) {
this.panel = CUORE.Dom.createElement('div', {
id: this.innerDivName(component.getName())
}, this.container);
@@ -12,6 +12,7 @@ CUORE.Renderers.Input = CUORE.Class(CUORE.Renderer, {
this.DOMInput = CUORE.Dom.createElement('input', {
type: component.type
}, this.panel);
+
},
updateWhenDrawn: function (component) {
View
4 src/Renderers/Cuore.Renderers.NumericSelector.js
@@ -6,8 +6,8 @@ CUORE.Renderers.NumericSelector = CUORE.Class(CUORE.Renderers.Input, {
this.valueDisplayed = null;
},
- draw: function (component) {
- CUORE.Renderers.NumericSelector.super.draw.call(this, component);
+ paint: function (component) {
+ CUORE.Renderers.NumericSelector.super.paint.call(this, component);
this._decorateInput();
this._addMinusButton(component);
View
4 src/Renderers/Cuore.Renderers.TimeRange.js
@@ -6,8 +6,8 @@ CUORE.Renderers.TimeRange = CUORE.Class(CUORE.Renderer, {
this.endHourSelect = null;
},
- draw: function(component) {
- CUORE.Renderers.TimeRange.super.draw.call(this, component);
+ paint: function(component) {
+ CUORE.Renderers.TimeRange.super.paint.call(this, component);
var componentSetStartHour = CUORE.Core.bind(component, component.setStartHour);
var componentSetEndHour = CUORE.Core.bind(component, component.setEndHour);

0 comments on commit 3de7a13

Please sign in to comment.
Something went wrong with that request. Please try again.