1. Створити сервіси для груп по аналогії дерева груп розділу.
2. Створити сервіс dq_DetailInGroup для таблиці tbl_DetailInGroup, з двома параметрами (GroupID, DetailID), порівняльними фільтрами по цим параметрам й відповідним полям таблиці.
3. У вікні реєстру вибраної деталі створити контейнер для стандартного вікна груп і відповідно налаштувати, як у груп розділу.
4. Додати у вікні реєстру для групи кнопок "Видалити" і в контекстному меню опції для видалення запису з групи (Напр.:amiDeleteFromCurrentGroup, amiDeleteFromGroup)
5. Для вікна реєстру створити скрипт обробки. Приклад вказаний нижче (Замість слова "Detail" можна вставити свою код. назву деталі).
//-----------------------------------------------------------------------------
// wnd_DetailGridAreaScript
//-----------------------------------------------------------------------------
var Script = {};
function InitializeWindowGroups(Window) {
InitializeGroups('tbl_DetailGroup', 'ds_DetailInGroup', 'DetailID');
OpenGroupsDataset();
}
function InitializeGroups(GroupTableUSI, ItemInGroupDatasetUSI, ParentItemFieldName, GroupDatasetUSI , ParentIDFieldName) {
var GroupsWindow = wndGroups.Window;
GroupsWindow.ComponentsByName('amiAddDynamicGroup').IsVisible = false;
Script.GroupsWindow = GroupsWindow;
if (IsEmptyValue(GroupDatasetUSI)) {
GroupDatasetUSI = 'ds_ItemGroup';
}
if (IsEmptyValue(ParentIDFieldName)) {
ParentIDFieldName = 'ParentGroupID';
}
SetAttribute(GroupsWindow, 'DatasetUSI', GroupDatasetUSI);
Script.GroupParentIDFieldName = ParentIDFieldName;
SetAttribute(GroupsWindow, 'TableUSI', GroupTableUSI);
SetAttribute(GroupsWindow, 'IDFieldName', 'ID');
SetAttribute(GroupsWindow, 'ParentIDFieldName', ParentIDFieldName);
SetAttribute(GroupsWindow, 'NameFieldName', 'Name');
SetAttribute(GroupsWindow, 'ItemInGroupDatasetUSI', ItemInGroupDatasetUSI);
SetAttribute(GroupsWindow, 'ParentItemFieldName', ParentItemFieldName);
SetAttribute(GroupsWindow, 'WorkspaceWindow', Self);
GroupsWindow.Prepare();
var Dataset = GetDatasetFromWindow(GroupsWindow, DefDatasetLinkName);
Script.GroupsDataset = Dataset;
Script.GroupsTreeGrid = GroupsWindow.ComponentsByName('grdData');
dlGroups.Dataset = Dataset;
}
function OpenGroupsDataset() {
var Dataset = dlGroups.Dataset;
OpenDatasetWithDisabledEvents(Dataset);
Script.GroupsWereInitialized = true;
LocateToRootGroup(Dataset, Script.GroupParentIDFieldName);
ExpandCurrentNode(Script.GroupsTreeGrid);
}
function RefreshGrid() {
dlData.Dataset.Close();
dlData.Dataset.Open();
}
function DeleteFromCurrentGroup() {
var GridDataset = dlData.Dataset;
var GroupsDataset = dlGroups.Dataset;
if ((GridDataset.State == dstInactive) || GridDataset.IsEmptyPage ||
(GroupsDataset.State == dstInactive) || GroupsDataset.IsEmptyPage) {
return;
}
var DetailID = GridDataset('ID');
var GroupID = GroupsDataset('ID');
if (ShowConfirmationDialog("Видалити запис з групи?") != mrYes) {
return;
}
var DeleteQuery = GetSingleItemByCode('dq_DetailInGroup', 'DeleteFromCurrentGroup');
var Parameters = DeleteQuery.Parameters;
Parameters('DetailID').Value = DetailID;
Parameters('GroupID').Value = GroupID;
DeleteQuery.Execute();
RefreshGrid();
}
//-----------------------------------------------------------------------------
// Event handler
//-----------------------------------------------------------------------------
function wnd_DetailGridAreaOnPrepare(Window) {
wnd_BaseGridAreaOnPrepare(Window);
InitializeWindowGroups(Window);
}
function dlGroupsOnDatasetAfterPositionChange(Dataset) {
if (Script.GroupsWereInitialized){
RefreshGrid();
}
}
function dlGroupsOnDatasetRefreshRecord(Dataset, KeyValue, AddNewRecordOnPage) {
RefreshGrid();
}
function dlGroupsOnDatasetAfterPositionChange(Dataset) {
RefreshGrid();
}
function dlDataOnDatasetBeforeOpen(Dataset, DoOpen) {
EnableDatasetFilters(dlData.Dataset, false, 'GroupID');
ApplyDatasetGroupIDFilter(Script.GroupsDataset, dlData.Dataset);
}
function wnd_DetailGridAreaOnNotify(ScriptableService, Sender, Message, Data) {
wnd_BaseGridAreaOnNotify(ScriptableService, Sender, Message, Data);
}
function amiDeleteFromGroupOnExecute(ActionMenuItem, Sender) {
DeleteFromCurrentGroup();
}
function amiDeleteFromCurrentGroupOnExecute(ActionMenuItem, Sender) {
DeleteFromCurrentGroup();
}
function dlDataOnDatasetRefreshRecord(Dataset, KeyValue, AddNewRecordOnPage) {
if (AddNewRecordOnPage) {
AddItemInGroup(dlGroups.Dataset, 'ds_DetailInGroup', KeyValue, 'DetailID');
}
RefreshGrid();
}
// wnd_DetailGridAreaScript
//-----------------------------------------------------------------------------
var Script = {};
function InitializeWindowGroups(Window) {
InitializeGroups('tbl_DetailGroup', 'ds_DetailInGroup', 'DetailID');
OpenGroupsDataset();
}
function InitializeGroups(GroupTableUSI, ItemInGroupDatasetUSI, ParentItemFieldName, GroupDatasetUSI , ParentIDFieldName) {
var GroupsWindow = wndGroups.Window;
GroupsWindow.ComponentsByName('amiAddDynamicGroup').IsVisible = false;
Script.GroupsWindow = GroupsWindow;
if (IsEmptyValue(GroupDatasetUSI)) {
GroupDatasetUSI = 'ds_ItemGroup';
}
if (IsEmptyValue(ParentIDFieldName)) {
ParentIDFieldName = 'ParentGroupID';
}
SetAttribute(GroupsWindow, 'DatasetUSI', GroupDatasetUSI);
Script.GroupParentIDFieldName = ParentIDFieldName;
SetAttribute(GroupsWindow, 'TableUSI', GroupTableUSI);
SetAttribute(GroupsWindow, 'IDFieldName', 'ID');
SetAttribute(GroupsWindow, 'ParentIDFieldName', ParentIDFieldName);
SetAttribute(GroupsWindow, 'NameFieldName', 'Name');
SetAttribute(GroupsWindow, 'ItemInGroupDatasetUSI', ItemInGroupDatasetUSI);
SetAttribute(GroupsWindow, 'ParentItemFieldName', ParentItemFieldName);
SetAttribute(GroupsWindow, 'WorkspaceWindow', Self);
GroupsWindow.Prepare();
var Dataset = GetDatasetFromWindow(GroupsWindow, DefDatasetLinkName);
Script.GroupsDataset = Dataset;
Script.GroupsTreeGrid = GroupsWindow.ComponentsByName('grdData');
dlGroups.Dataset = Dataset;
}
function OpenGroupsDataset() {
var Dataset = dlGroups.Dataset;
OpenDatasetWithDisabledEvents(Dataset);
Script.GroupsWereInitialized = true;
LocateToRootGroup(Dataset, Script.GroupParentIDFieldName);
ExpandCurrentNode(Script.GroupsTreeGrid);
}
function RefreshGrid() {
dlData.Dataset.Close();
dlData.Dataset.Open();
}
function DeleteFromCurrentGroup() {
var GridDataset = dlData.Dataset;
var GroupsDataset = dlGroups.Dataset;
if ((GridDataset.State == dstInactive) || GridDataset.IsEmptyPage ||
(GroupsDataset.State == dstInactive) || GroupsDataset.IsEmptyPage) {
return;
}
var DetailID = GridDataset('ID');
var GroupID = GroupsDataset('ID');
if (ShowConfirmationDialog("Видалити запис з групи?") != mrYes) {
return;
}
var DeleteQuery = GetSingleItemByCode('dq_DetailInGroup', 'DeleteFromCurrentGroup');
var Parameters = DeleteQuery.Parameters;
Parameters('DetailID').Value = DetailID;
Parameters('GroupID').Value = GroupID;
DeleteQuery.Execute();
RefreshGrid();
}
//-----------------------------------------------------------------------------
// Event handler
//-----------------------------------------------------------------------------
function wnd_DetailGridAreaOnPrepare(Window) {
wnd_BaseGridAreaOnPrepare(Window);
InitializeWindowGroups(Window);
}
function dlGroupsOnDatasetAfterPositionChange(Dataset) {
if (Script.GroupsWereInitialized){
RefreshGrid();
}
}
function dlGroupsOnDatasetRefreshRecord(Dataset, KeyValue, AddNewRecordOnPage) {
RefreshGrid();
}
function dlGroupsOnDatasetAfterPositionChange(Dataset) {
RefreshGrid();
}
function dlDataOnDatasetBeforeOpen(Dataset, DoOpen) {
EnableDatasetFilters(dlData.Dataset, false, 'GroupID');
ApplyDatasetGroupIDFilter(Script.GroupsDataset, dlData.Dataset);
}
function wnd_DetailGridAreaOnNotify(ScriptableService, Sender, Message, Data) {
wnd_BaseGridAreaOnNotify(ScriptableService, Sender, Message, Data);
}
function amiDeleteFromGroupOnExecute(ActionMenuItem, Sender) {
DeleteFromCurrentGroup();
}
function amiDeleteFromCurrentGroupOnExecute(ActionMenuItem, Sender) {
DeleteFromCurrentGroup();
}
function dlDataOnDatasetRefreshRecord(Dataset, KeyValue, AddNewRecordOnPage) {
if (AddNewRecordOnPage) {
AddItemInGroup(dlGroups.Dataset, 'ds_DetailInGroup', KeyValue, 'DetailID');
}
RefreshGrid();
}
Благодарність Артёму Репко за допомогу у вирішенні даного питання.
Показать все комментарии
Войдите или зарегистрируйтесь, что бы комментировать