Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor HtmlOnCondition and Validators Editors, surveyjs/survey-libr…
- Loading branch information
1 parent
2c76e40
commit 3372819
Showing
10 changed files
with
200 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import * as ko from "knockout"; | ||
import * as Survey from "survey-knockout"; | ||
import { SurveyPropertyItemsEditor } from "./propertyItemsEditor"; | ||
import { SurveyQuestionEditor } from "../questionEditors/questionEditor"; | ||
|
||
export class SurveyPropertyOneSelectedEditor extends SurveyPropertyItemsEditor { | ||
public selectedObjectEditor: any; | ||
public koSelected: any; | ||
public koAvailableClasses: any; | ||
private currentObjClassName: string; | ||
constructor(property: Survey.JsonObjectProperty) { | ||
super(property); | ||
var self = this; | ||
this.koAvailableClasses = ko.observableArray(this.getAvailableClasses()); | ||
this.selectedObjectEditor = ko.observable(null); | ||
this.koSelected = ko.observable(null); | ||
this.koSelected.subscribe(function(newValue) { | ||
if (!!self.selectedObjectEditor()) { | ||
self.selectedObjectEditor().apply(); | ||
} | ||
var editor = | ||
newValue != null | ||
? new SurveyQuestionEditor(newValue.obj, null, null, self.options) | ||
: null; | ||
self.selectedObjectEditor(editor); | ||
}); | ||
this.onDeleteClick = function() { | ||
self.koItems.remove(self.koSelected()); | ||
}; | ||
this.onAddClick = function(item: any) { | ||
self.addNewItem(!!item ? item.value : null); | ||
}; | ||
} | ||
public get editorTypeTemplate(): string { | ||
return "oneselected"; | ||
} | ||
public get editorType(): string { | ||
return "oneselected"; | ||
} | ||
protected createOneSelectedItem(obj: any): SurveyPropertyOneSelectedItem { | ||
return new SurveyPropertyOneSelectedItem(obj); | ||
} | ||
protected getObjClassName() { | ||
return this.currentObjClassName; | ||
} | ||
protected getAvailableClasses(): Array<any> { | ||
return []; | ||
} | ||
protected addNewItem(className: string) { | ||
this.currentObjClassName = className; | ||
this.AddItem(); | ||
this.koSelected(this.koItems()[this.koItems().length - 1]); | ||
} | ||
protected onValueChanged() { | ||
super.onValueChanged(); | ||
if (this.koSelected) { | ||
this.koSelected(this.koItems().length > 0 ? this.koItems()[0] : null); | ||
} | ||
} | ||
protected createEditorItem(item: any) { | ||
var jsonObj = new Survey.JsonObject(); | ||
var newItem = Survey.JsonObject.metaData.createClass(item.getType()); | ||
jsonObj.toObject(item, newItem); | ||
this.setItemProperties(newItem); | ||
return this.createOneSelectedItem(newItem); | ||
} | ||
protected createNewEditorItem(): any { | ||
return this.createEditorItem( | ||
Survey.JsonObject.metaData.createClass(this.getObjClassName()) | ||
); | ||
} | ||
protected createItemFromEditorItem(editorItem: any) { | ||
var item = <SurveyPropertyOneSelectedItem>editorItem; | ||
delete item.obj["survey"]; | ||
return item.obj; | ||
} | ||
private setItemProperties(obj: any) { | ||
if (this.object) { | ||
obj["survey"] = this.object.survey; | ||
} | ||
obj.locOwner = this; | ||
} | ||
} | ||
|
||
export class SurveyPropertyOneSelectedItem { | ||
public koText: any; | ||
constructor(public obj: Survey.Base) { | ||
this.koText = ko.observable(this.getText()); | ||
} | ||
public getText() { | ||
return ""; | ||
} | ||
public objectChanged() { | ||
this.koText(this.getText()); | ||
} | ||
} |
Oops, something went wrong.