com.smartclient.debug.public.sc.client.widgets.EntityEditor.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of smartgwt Show documentation
Show all versions of smartgwt Show documentation
SmartGWT - GWT API's for SmartClient
The newest version!
/*
* Isomorphic SmartClient
* Version SC_SNAPSHOT-2011-08-08 (2011-08-08)
* Copyright(c) 1998 and beyond Isomorphic Software, Inc. All rights reserved.
* "SmartClient" is a trademark of Isomorphic Software, Inc.
*
* [email protected]
*
* http://smartclient.com/license
*/
if (isc.Portal) {
isc.defineClass("EntityEditorHeader", "VLayout");
isc.EntityEditorHeader.addProperties({
height: 1,
padding: 10,
border: "2px solid black",
headerLayoutDefaults: {
_constructor: "VLayout",
width: "100%",
height: 1,
membersMargin: 5
},
headerLabelTitle: "Editing ${entityType}
"+
"This UI lets you edit the entire data-structure for this Entity-type
",
headerLabelDefaults: {
_constructor: "Label",
width: "100%",
height: 30,
autoParent: "headerLayout"
},
showDetailLabel: false,
defaultDetailLabelTitle: "This UI lets you edit the entire data-structure for this Entity-type
",
detailLabelTitle: "$entityComment
",
detailLabelDefaults: {
_constructor: "Label",
width: "100%",
height: 20,
autoParent: "headerLayout"
},
unknownEntityTitle: "[Unknown Entity-type]",
initWidget : function () {
var headerTitle = this.headerLabelTitle;
var detailTitle = this.detailLabelTitle;
if (this.dataSource) this.getDataSource(this.dataSource);
if (!this.entityName) this.entityName = this.getEntityName(this.dataSource);
if (!this.entityComment) this.entityComment = this.getEntityComment(this.dataSource);
if (this.entityName)
headerTitle = headerTitle.evalDynamicString(this, { entityType: this.entityName });
if (this.entityComment)
detailTitle = detailTitle.evalDynamicString(this, { entityType: this.entityComment });
this.headerLayout = this.addAutoChild("headerLayout");
this.headerLabel = this.addAutoChild("headerLabel", {contents: headerTitle});
this.detailLabel = this.addAutoChild("detailLabel", {contents: detailTitle});
this.headerLayout.addMembers([this.headerLabel, this.detailLabel]);
//this.headerLayout.addMember(this.detailLabel);
this.addMember(this.headerLayout);
},
getEntityName : function (dataSource) {
var result = this.unknownEntityTitle;
if (dataSource) {
if (isc.isA.Function(dataSource.getEntityName))
result = dataSource.getEntityName();
else result = dataSource.ID;
}
return result;
},
getEntityComment : function (dataSource) {
var result = this.defaultDetailLabelTitle;
if (dataSource) {
if (isc.isA.Function(dataSource.getEntityComment))
result = dataSource.getEntityComment();
else result = "Allows hierarchical editing of data in "+dataSource.ID+" DataSource";
}
return result;
}
});
isc.defineClass("EntityEditorForm", "Portlet").addProperties({
//isc.defineClass("EntityEditorForm", "VLayout").addProperties({
//height: 1,
//padding: 10,
addButtonDefaults: {
_constructor: "IButton",
title: "Add",
autoFit: true,
layoutAlign: "right",
click : function () {
this.creator.addRecord();
}
},
formDefaults: {
_constructor: "DynamicForm",
numCols: 6,
colWidths: ["*", "*", "*", "*", "*", "*"],
width: "100%",
implicitSave: true,
initWidget : function () {
this.Super("initWidget", arguments);
if (this.record && this.relation) {
var criteria = {};
if (!this.relation.direction) {
// top-level entity - fetch via direct pk criteria
criteria[this.relation.baseFieldName] = this.record[this.relation.baseFieldName];
} else {
// we're a child-entity of some parent which refers to us by PK - fetch via a link
criteria[this.relation.baseFieldName] = this.record[this.relation.relatedFieldName];
}
this.fetchData(criteria);
}
},
implicitSaveCallback : function (data) {
if (!this.record || !this.record[this.relation.baseFieldName]) {
this.creator.setRecord(data);
this.setValues(data);
this.saveOperationType = "update";
}
}
},
initWidget : function () {
this.Super("initWidget", arguments);
this.addAutoChild("addButton");
this.addAutoChild("form",
isc.addProperties({}, this.formProperties,
{
dataSource: this.dataSource,
title: this.title,
record: this.record,
relation: this.relation
}
)
);
if (isc.isA.Portlet(this)) this.addItems([this.addButton, this.form]);
else this.addMembers([this.addButton, this.form]);
},
fetchData : function () {
var criteria = {};
if (!this.relation.direction) {
if (this.isTopLevel())
// top-level entity - fetch via direct pk criteria
criteria[this.relation.baseFieldName] = this.record[this.relation.baseFieldName];
} else {
// we're a child-entity of some parent which refers to us by PK - fetch via a link
criteria[this.relation.baseFieldName] = this.record[this.relation.relatedFieldName];
}
this.form.fetchData(criteria);
},
addRecord : function () {
var criteria = {};
if (!this.relation.direction) {
if (!this.isTopLevel())
criteria[this.relation.baseFieldName] = this.record[this.relation.baseFieldName];
} else {
// we're a child-entity of some parent which refers to us by PK - fetch via a link
criteria[this.relation.baseFieldName] = this.record[this.relation.relatedFieldName];
}
this.record = criteria;
this.form.editNewRecord(criteria);
//this.creator.updateTopLevel();
},
isTopLevel : function () {
return this.relation.relatedDS == null;
},
setRecord : function (record) {
if (this.isTopLevel()) {
this.creator.updateTopLevel();
} else {
this.fetchData();
}
this.record = record;
this.form.record = record;
if (this.addButton) this.addButton.setDisabled(this.record == null);
},
getData : function () {
return null;
},
getCriteria : function () {
return this.form.getValuesAsCriteria();
},
enterSearchMode : function (criteria) {
this.addButton.setDisabled(true);
this.record = this.form.record = null;
this.form.implicitSave = false;
this.form.setData([]);
if (criteria) this.form.setValues(criteria);
},
exitSearchMode : function () {
}
});
isc.defineClass("EntityEditorGrid", "Portlet").addProperties({
//isc.defineClass("EntityEditorGrid", "VLayout").addProperties({
// overflow: "visible",
// autoSize: true,
//padding: 10,
addButtonDefaults: {
_constructor: "IButton",
title: "Add",
autoFit: true,
layoutAlign: "right",
click : function () {
this.creator.addRecord();
}
},
gridDefaults: {
_constructor: "ListGrid",
width: "100%",
height: "100%",
// autoFitData: "vertical",
autoFitMaxRecords: 4,
autoFetchData: false,
canEdit: true,
autoSaveEdits: true,
initWidget : function () {
if (this.record && this.relation) {
this.initialCriteria = {};
this.initialCriteria[this.relation.baseFieldName] = this.record[this.relation.relatedFieldName];
}
this.Super("initWidget", arguments);
}
},
initWidget : function () {
this.addAutoChild("addButton");
if (!isc.isA.DataSource(this.dataSource))
this.dataSource = isc.DS.get(this.dataSource);
this.addAutoChild("grid",
isc.addProperties({}, this.gridProperties,
{
dataSource: this.dataSource,
title: this.title,
record: this.record,
relation: this.relation
}
)
);
if (this.record) this.fetchData();
if (this.addButton) this.addButton.setDisabled(this.record == null);
if (isc.isA.Portlet(this)) this.addItems([this.addButton, this.grid]);
else this.addMembers([this.addButton, this.grid]);
this.Super("initWidget", arguments);
},
setData : function (data) {
},
fetchData : function () {
var criteria = {};
if (this.record) {
// we're a child-entity of some parent which refers to us by PK - fetch via a link
criteria[this.relation.baseFieldName] = this.record[this.relation.relatedFieldName];
}
this.grid.fetchData(criteria);
},
addRecord : function () {
var criteria = {};
// we're a child-entity of some parent which refers to us by PK - fetch via a link
criteria[this.relation.baseFieldName] = this.record[this.relation.relatedFieldName];
this.grid.startEditingNew(criteria);
},
setRecord : function (record) {
this.record = record;
this.fetchData();
if (this.addButton) this.addButton.setDisabled(this.record == null);
},
getData : function () {
return null;
},
getCriteria : function () {
return this.grid.getFilterEditorCriteria();
},
enterSearchMode : function (criteria) {
this.addButton.setDisabled(true);
this.record = this.grid.record = null;
//this.grid.clearCriteria();
this.grid.setData([]);
this.grid.setShowFilterEditor(true);
//this.grid.redraw();
//this.redraw();
if (criteria) this.grid.setCriteria(criteria);
},
exitSearchMode : function () {
}
});
// Entity Editor
// ---------------------------------------------------------------------------------------
// Interface for defining and editing a complete data-structure for a database entity.
//> @class EntityEditor
// Interface for defining and editing a complete data-structure for a database entity.
//
// @visibility entityEditor
//<
isc.defineClass("EntityEditor", "VLayout");
isc.EntityEditor.addProperties({
//height: 1,
membersMargin: 10,
padding: 10,
//> @attr entityEditor.dataSource (DataSource : null : IR)
// The dataSource providing the initial top-level Entity, which we'll check for
// relational links and also display the data from those tables in appropriate UIs.
//
// @visibility entityEditor
//<
dataSource: "",
modeFormDefaults: {
_constructor: "DynamicForm",
height: 1,
width: "100%",
fields: [
{name: "edit", title: "options", defaultToFirstOption: true,
valueMap: ["Edit", "Search"],
changed : function (form, item, value) {
form.creator.setMode(value);
}
}
]
},
formEntityDefaults: {
_constructor: "EntityEditorForm",
height: 1,
width: "100%"
},
gridEntityDefaults: {
_constructor: "EntityEditorGrid",
height: 1,
width: "100%"
},
showTabset: false,
tabsetDefaults: {
_constructor: "TabSet",
width: "100%",
height: "100%"
},
//showPortal: false,
portalDefaults: {
_constructor: "PortalLayout",
width: "100%",
height: "100%",
showColumnMenus: false,
numColumns: 1
},
getDataSourceHierarchy : function (ds, doneList) {
var result = [];
if (!isc.isA.DataSource(ds))
ds = isc.DS.getDataSource(ds);
if (!isc.isA.DataSource(ds)) {
this.logWarn("No datasource provided..");
return result;
}
if (!doneList) doneList = [];
if (doneList.contains(ds.ID)) {
// already processed this DS - skip it now
return null;
}
var rawFields = isc.getValues(ds.getFields()),
dsFields = []
;
for (var i=0; i 0) {
if (this.showTabset) {
for (var i=this.tabset.tabs.length-1; i>=0; i--) {
this.entities[i].markForDestroy();
this.tabset.removeTab(i);
}
} else if (this.portal) {
this.portal.members.removeAll();
for (var i=this.entities.length-1; i>=0; i--) {
this.entities[i].markForDestroy();
}
} else {
for (var i=this.members.length-1; i>=1; i--) {
this.removeMember(i);
this.entities[i-1].markForDestroy();
}
}
}
this.entities = [];
this.record = null;
},
showEntity : function () {
var tree = this.entityTree;
if (!this.entities) this.entities = [];
if (!this.entityTree) return;
this.addEditor(tree);
this.topLevelComponent = this.entities[0];
if (tree && tree.relations && tree.relations.length > 0) {
for (var i=0; i 0) {
for (i=0; i 0) {
for (i=0; i