My app contains a TabSet with many tabs. These tabs are created dynamicly basing on data. Content of each tab is created on the server. I use ViewLoader for that.
Content is created on the server bacause it dynamical. It's autogenerated UI (kind of scaffolding).
ViewLoader controller (which returns UI for tabs) creates each time similar UI based on url's parameters ('entityType' here).
Returned UI contains several connected isc-objects: DynamicForm, ListGrid and ContextMenu.
Something like this (code between <%%> is server asp.net mvc code):
It works fine untill there's only one tab. But as a user opens a next tab object names start dublicating. And ListGrid on some tab starts using ContextMenu from tab has been opened previously and so on.
I can understand why that's happening, just because all objects are in the global scope.
My question is about what are good patterns&practices in such situations. How to isolate objects on deferent tabs?
One approach I can see is to use string IDs instead of variables and generate unique ID in server code. That would probably work in general but a problem I can see is using IDs in string methods.
Let's look a ContextMenu's item. It has enableIf attibute with JS-code:
enableIf: "list.getSelectedRecord() != null"
"list" is a name in global space. So I have to write something like this:
"list<%= ViewData["UniqueId"] %>.getSelectedRecord() != null"
i.e. combine client with server. It's ugly!
Is there any other approaches?
Code:
centerTabSet.addTab({ title: entityTypeDesc, autoDraw: true, canClose: true, ID: "centerTabSet_" + entityTypeName, pane: isc.ViewLoader.create({ viewURL: "<%: Url.Content("~") %>ViewLoader/getListPart?entityType=" + entityTypeName })
ViewLoader controller (which returns UI for tabs) creates each time similar UI based on url's parameters ('entityType' here).
Returned UI contains several connected isc-objects: DynamicForm, ListGrid and ContextMenu.
Something like this (code between <%%> is server asp.net mvc code):
Code:
var datasource = isc.DataSource.create({ dataFormat: "xml", dataURL: "<%= ViewData["DataURL"]%>", recordXPath: "//Rows/R", fields:<%= ViewData["FieldsJsonArray"] %>, }); var filter = isc.SearchForm.create({ dataSource: "datasource", fields: <%= ViewData["FilterFieldsJsonArray"] %>, saveOnEnter: true, submitValues : "refreshButton.doSearch()" }); var listContextMenu = isc.Menu.create({ data : [ {title: "Edit", enableIf: "list.getSelectedRecord() != null", click: "openEditorInDialog()"}, ] }); var list = isc.ListGrid.create({ selectionType: "single", contextMenu: listContextMenu, autoFetchData: true, dataSource: "datasource" });
I can understand why that's happening, just because all objects are in the global scope.
My question is about what are good patterns&practices in such situations. How to isolate objects on deferent tabs?
One approach I can see is to use string IDs instead of variables and generate unique ID in server code. That would probably work in general but a problem I can see is using IDs in string methods.
Let's look a ContextMenu's item. It has enableIf attibute with JS-code:
enableIf: "list.getSelectedRecord() != null"
"list" is a name in global space. So I have to write something like this:
"list<%= ViewData["UniqueId"] %>.getSelectedRecord() != null"
i.e. combine client with server. It's ugly!
Is there any other approaches?
Comment