Skip to content

Commit

Permalink
Introduce getTemplate function in Base object: surveyjs#714
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Telnov (DevExpress) authored and Andrew Telnov (DevExpress) committed Oct 13, 2017
1 parent 43c03a3 commit 42737fc
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ export class Base {
* Returns the type of the object as a string as it represents in the json.
*/
public getType(): string { return "base"; }
/**
* Returns the element template name without prefix. Typically it equals to getType()
* @see getType
*/
public getTemplate(): string { return this.getType(); }
/**
* Returns true if the object is loading from Json at the current moment.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/jsonobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@ export class JsonMetadata {
private createCustomType(name: string, creator: any): any {
var res = creator();
res.customTypeName = name;
res.customTemplateName = res.getTemplate ? res.getTemplate() : res.getType();
res.getType = function() { return res.customTypeName; };
res.getTemplate = function() { return res.customTemplateName; };
CustomPropertiesCollection.createProperties(res);
return res;
}
Expand Down
2 changes: 1 addition & 1 deletion src/knockout/koquestionbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ export class QuestionImplementorBase {
private getTemplateName(): string {
if (this.question.customWidget && !this.question.customWidget.widgetJson.isDefaultRender)
return "survey-widget-" + this.question.customWidget.name;
return "survey-question-" + this.question.getType();
return "survey-question-" + this.question.getTemplate();
}
}
4 changes: 2 additions & 2 deletions src/knockout/kosurvey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class Survey extends SurveyModel {
}
element = this.renderedElement;
if (!element) return;
element.innerHTML = this.getTemplate();
element.innerHTML = this.getHtmlTemplate();
self.applyBinding();
}
public koEventAfterRender(element, survey) {
Expand All @@ -81,7 +81,7 @@ export class Survey extends SurveyModel {
this.updateKoCurrentPage();
}
protected createNewPage(name: string) { return new Page(name); }
protected getTemplate(): string { return koTemplate; }
protected getHtmlTemplate(): string { return koTemplate; }
protected onBeforeCreating() {
var self = this;
this.dummyObservable = ko.observable(0);
Expand Down
2 changes: 1 addition & 1 deletion src/react/reactSurvey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export class Survey extends React.Component<any, any> implements ISurveyCreator

//ISurveyCreator
public createQuestionElement(question: QuestionBase): JSX.Element {
return ReactQuestionFactory.Instance.createQuestion(question.getType(), {
return ReactQuestionFactory.Instance.createQuestion(question.getTemplate(), {
question: question, isDisplayMode: question.isReadOnly, creator: this
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/vue/customwidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
}
get componentName(): string {
if(this.hasVueComponent) return this.question.customWidget.name;
return "survey-" + this.question.getType();
return "survey-" + this.question.getTemplate();
}
mounted() {
this.question.customWidget.afterRender(this.question, this.$el);
Expand Down
2 changes: 1 addition & 1 deletion src/vue/element.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
if(element.customWidget) {
return "survey-customwidget";
}
return 'survey-' + element.getType();
return 'survey-' + element.getTemplate();
}
mounted() {
if(this.survey && !this.element.isPanel) {
Expand Down
3 changes: 2 additions & 1 deletion tests/jsonobjecttests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,5 +580,6 @@ QUnit.test("Create object with virtual type by using parent constructor", funct
assert.equal(truck.maxWeight, 10000, "maxWeight is deserialized");
assert.equal(truck["description"], "some text", "added property is deserialized");
assert.equal(truck["isCustom"], true, "added property created if it is default");
assert.equal(truck.getType(), "customtruck", "type is truck");
assert.equal(truck.getType(), "customtruck", "type is customtruck");
assert.equal(truck.getTemplate(), "truck", "template is truck");
});

0 comments on commit 42737fc

Please sign in to comment.