Exemple #1
0
        public void LoadDefaultValues()
        {
            if (SetDefaultValues)
            {
                Border = EnableBorder;
                if (this.IdType == 0)
                    this.IdType = IdType.Int;

                if (string.IsNullOrEmpty(Layout))
                    Layout = "fit";

                #region TopBar

                if (!DisableTopBar)
                {
                    Ext.Net.Toolbar toolBar = null;
                    bool hasToolBar = this.TopBar != null && this.TopBar.Count > 0;
                    if (hasToolBar)
                        toolBar = (Ext.Net.Toolbar)this.TopBar.First();
                    else
                        toolBar = new Ext.Net.Toolbar { ID = string.Format("toolbar{0}", ID) };

                    SubmitButton btnSave = null;
                    if (!DisableSave && (HasAddPermission || HasUpdatePermission))
                    {
                        btnSave = new SubmitButton
                        {
                            ID = string.Format("btnSave{0}", ID),
                            Text = "Save",
                            FormPanelID = this.FormPanelID,
                            DisableSuccessHandler = this.DisableSuccessHandler,
                            DisableFailureHandler = this.DisableFailureHandler
                        };
                    }

                    SubmitButton btnSaveAndNext = null;
                    if (!DisableSaveAndNew && HasAddPermission)
                    {
                        btnSaveAndNext = new SubmitButton
                        {
                            ID = string.Format("btnSaveAndNext{0}", ID),
                            Text = "Save and New",
                            FormPanelID = this.FormPanelID,
                            DisableSuccessHandler = this.DisableSuccessHandler,
                            DisableFailureHandler = this.DisableFailureHandler,
                            Icon = Ext.Net.Icon.Add,
                            SetNew = true
                        };
                    }

                    Ext.Net.Button btnDelete = null;
                    if (!DisableDelete && HasDeletePermission)
                    {
                        btnDelete = new Ext.Net.Button {
                            ID = string.Format("btnDelete{0}", ID),
                            Text = "Delete",
                            Icon = Ext.Net.Icon.Cross
                        };

                        btnDelete.DirectEvents.Click.Url = DeleteUrl;
                        btnDelete.DirectEvents.Click.CleanRequest = true;
                        btnDelete.DirectEvents.Click.Before = (BeforeDeleteHandler ?? string.Empty) + "#{" + ID + "}.getEl().mask('Deleting...');";
                        btnDelete.DirectEvents.Click.Failure = "#{" + ID + "}.getEl().unmask(); if(result.extraParams && result.extraParams.hasPermission && result.extraParams.hasPermission == '0') { Ax.ShowNotification('Warning', result.extraParams.msg, 'icon-exclamation');  } else { Ax.ShowNotification('Warning', result.extraParams.msg, 'icon-exclamation'); }" + (DeleteFailureHandler ?? string.Empty);

                        btnDelete.DirectEvents.Click.Confirmation.ConfirmRequest = true;
                        btnDelete.DirectEvents.Click.Confirmation.Title = "Alert";
                        btnDelete.DirectEvents.Click.Confirmation.Message = "Are you sure?";

                        btnDelete.DirectEvents.Click.ExtraParams.Add(
                            new Ext.Net.Parameter {
                                Name = "rows",
                                Value = "[#{" + IDProperty + "}.value]",
                                Mode = Ext.Net.ParameterMode.Raw
                            });
                    }

                    Ext.Net.Button btnClose = null;
                    if (!DisableClose)
                    {
                        btnClose = new Ext.Net.Button {
                            ID = string.Format("btnClose{0}", ID),
                            Text = "Close",
                            Icon = Ext.Net.Icon.Cancel
                        };
                    }

                    #region ToolbarOrder

                    bool isOrdered = false;

                    if (!string.IsNullOrEmpty(ToolbarOrder) && ToolbarOrder.IndexOf(',') != -1)
                    {
                        string[] buttons = ToolbarOrder.Split(',');
                        int totalItemCount = toolBar.Items.Count;
                        int controlItemCount = 4;
                        if (buttons.Length == totalItemCount + controlItemCount)
                        {
                            isOrdered = true;
                            Ext.Net.Component[] toolbarItems = new Ext.Net.Component[totalItemCount];
                            toolBar.Items.CopyTo(toolbarItems);
                            toolBar.Items.Clear();
                            string controlIndex;
                            int index = 0;
                            int j = 0;
                            for (int i = 0; i < buttons.Length; i++)
                            {
                                controlIndex = buttons[i].ToLower().Trim();

                                if (controlIndex == "0")
                                {
                                    if (btnSave != null) { toolBar.Items.Insert(j, btnSave); j++; }
                                }
                                else if (controlIndex == "1")
                                {
                                    if (btnSaveAndNext != null) { toolBar.Items.Insert(j, btnSaveAndNext); j++; }
                                }
                                else if (controlIndex == "2")
                                {
                                    if (btnDelete != null) { toolBar.Items.Insert(j, btnDelete); j++; }
                                }
                                else if (controlIndex == "3")
                                {
                                    if (btnClose != null) { toolBar.Items.Insert(j, btnClose); j++; }
                                }
                                else
                                {
                                    if (Thesis.Common.Helpers.Ax.TryParse(controlIndex, ref index) && index >= controlItemCount)
                                    {
                                        toolBar.Items.Insert(j, toolbarItems[index - controlItemCount]);
                                        j++;
                                    }
                                }
                            }
                        }
                    }

                    if(!isOrdered)
                    {
                        int index = 0;
                        if (btnSave != null) { toolBar.Items.Insert(index, btnSave); index++; }
                        if (btnSaveAndNext != null) { toolBar.Items.Insert(index, btnSaveAndNext); index++; }
                        if (btnDelete != null) { toolBar.Items.Insert(index, btnDelete); index++; }
                        if (btnClose != null) { toolBar.Items.Add(btnClose); }
                    }

                    #endregion

                    if (!hasToolBar && toolBar.Items.Count > 0)
                        TopBar.Add(toolBar);
                }

                #endregion

                if (!string.IsNullOrEmpty(IDProperty))
                    Listeners.Render.Handler += string.Format("var __isNew = {0}.value == '{1}'; var __btnDel = Ext.getCmp('btnDelete{2}'); if(__btnDel) __btnDel.setDisabled(__isNew);", IDProperty, (this.IdType == IdType.Guid ? Guid.Empty.ToString() : "0"), this.ID);

                if (!string.IsNullOrEmpty(SetDefaultUIValuesFn))
                    Listeners.Render.Handler += string.Format("{0}();", SetDefaultUIValuesFn);

                if (CheckDirty)
                {
                    this.Items.Add(new Ext.Net.Hidden() { ID = string.Format("hdnFormObject_{0}", this.ID) });
                    Listeners.AfterRender.Handler += string.Format("#{{hdnFormObject_{0}}}.setValue(Ax.ClearDirtyForm(#{{{1}}}));", this.ID, this.FormPanelID);
                    Listeners.AfterRender.Buffer = CheckDirtyBuffer > 0 ? CheckDirtyBuffer : 650;
                }
            }
        }
Exemple #2
0
        public void LoadDefaultValues()
        {
            if (SetDefaultValues)
            {
                StripeRows = !DisableStripeRows;
                Border = EnableBorder;
                TrackMouseOver = !DisableTrackMouseOver;

                #region Permissions

                bool hasAddPermission = true, hasDeletePermission = true;
                if (!string.IsNullOrEmpty(this.Module))
                {
                    List<ProcessTypes> permissions = ModuleAuthorizeService.GetModulePermissionsByModule(this.Module);
                    if (permissions == null)
                    {
                        DisableVisible();
                        return;
                    }
                    else
                    {
                        if (permissions.IndexOf(ProcessTypes.View) == -1) { DisableVisible(); return; }
                        hasAddPermission = permissions.IndexOf(ProcessTypes.Add) != -1;
                        hasDeletePermission = permissions.IndexOf(ProcessTypes.Delete) != -1;
                    }
                }

                #endregion

                #region TopBar

                Ext.Net.Button btnDelete = null;

                if (!DisableTopbar)
                {
                    Ext.Net.Toolbar toolbar = null;
                    bool hasToolBar = this.TopBar != null && this.TopBar.Count > 0;
                    if (!hasToolBar)
                        toolbar = new Ext.Net.Toolbar() { ID = string.Format("toolbar{0}", ID) };
                    else
                    {
                        toolbar = (Ext.Net.Toolbar)this.TopBar.First();
                    }

                    #region BtnAdd

                    Ext.Net.Button btnAdd = null;
                    if (hasAddPermission && !DisableAdd && (DetailPage != null))
                    {
                        btnAdd = new Ext.Net.Button {
                            ID = string.Format("btnAdd{0}", this.ID),
                            Text = "Add",
                            Icon = Ext.Net.Icon.Add
                        };

                        if (DetailPage != null)
                            btnAdd.Listeners.Click.Handler = DetailPageScript(true);
                   }

                    #endregion

                    #region BtnDelete

                    if (hasDeletePermission && !DisableDelete && !string.IsNullOrEmpty(DeleteUrl))
                    {
                        btnDelete = new Ext.Net.Button {
                            ID = string.Format("btnDelete{0}", this.ID),
                            Text = "Delete",
                            Icon = Ext.Net.Icon.Delete,
                            Disabled = true
                        };

                        DeleteDirectEvent(btnDelete.DirectEvents.Click);
                    }

                    #endregion

                    #region ToogleSearch

                    Ext.Net.Button btnToogleSearch = null;
                    if (this.EnableSearch && this.ToggleSearch)
                    {
                        btnToogleSearch = new Ext.Net.Button() {
                            ID = string.Format("btnToogleSearch_{0}", this.ID),
                            Icon = Ext.Net.Icon.TableLightning,
                            Text="Filter",
                            EnableToggle=true
                        };
                        btnToogleSearch.Listeners.Click.Handler = string.Format("#{{panel_search_{0}}}.toggleCollapse();", this.ID);
                    }

                    #endregion

                    #region BtnExport

                    Ext.Net.Button btnExport = null;

                    if (!DisableExport && (!DisableExcelExport || !DisableXmlExport || !DisableCsvExport))
                    {
                        btnExport = new Ext.Net.Button {
                            ID = string.Format("btnExport{0}", this.ID),
                            Text = "Export",
                            Icon = Ext.Net.Icon.DatabaseGo
                        };

                        Ext.Net.Menu exportMenu = new Ext.Net.Menu();

                        if(!DisableExcelExport) exportMenu.Items.Add(new Ext.Net.MenuItem { Text = "Excel", Icon = Ext.Net.Icon.PageExcel });
                        if(!DisableXmlExport)   exportMenu.Items.Add(new Ext.Net.MenuItem { Text = "XML", Icon = Ext.Net.Icon.PageCode });
                        if(!DisableCsvExport)   exportMenu.Items.Add(new Ext.Net.MenuItem { Text = "CSV", Icon = Ext.Net.Icon.PageAttach });

                        exportMenu.DirectEvents.Click.IsUpload = true;
                        exportMenu.DirectEvents.Click.CleanRequest = true;
                        exportMenu.DirectEvents.Click.Url = ((Ext.Net.HttpProxy)this.Store[0].Proxy[0]).Url;
                        exportMenu.DirectEvents.Click.FormID = this.FormID ?? "proxyForm";

                        exportMenu.DirectEvents.Click.ExtraParams.AddRange(
                            new List<Ext.Net.Parameter> {
                                new Ext.Net.Parameter{ Name="dir",  Value = "#{" + this.ID + "}.store.sortInfo.direction", Mode= Ext.Net.ParameterMode.Raw },
                                new Ext.Net.Parameter{ Name="sort", Value = "#{" + this.ID + "}.store.sortInfo.field", Mode= Ext.Net.ParameterMode.Raw },
                                new Ext.Net.Parameter{ Name="ExportFormat", Value = "menuItem.iconCls", Mode= Ext.Net.ParameterMode.Raw },
                                new Ext.Net.Parameter{ Name="IsExport", Value = "true" }
                            });

                        string[] exportParams = { "start", "limit", "dir", "sort", "exportformat", "isexport" };

                        foreach (Ext.Net.Parameter param in this.Store.Primary.BaseParams)
                        {
                            if(Array.IndexOf(exportParams, param.Name.ToLower().Trim()) == -1)
                                exportMenu.DirectEvents.Click.ExtraParams.Add(param);
                        }

                        btnExport.Menu.Add(exportMenu);
                    }

                    #endregion

                    #region ToolbarOrder

                    bool isOrdered = false;

                    if (!string.IsNullOrEmpty(ToolbarOrder) && ToolbarOrder.IndexOf(',') != -1)
                    {
                        string[] buttons = ToolbarOrder.Split(',');
                        int totalItemCount = toolbar.Items.Count;
                        int controlItemCount = 3;
                        if (buttons.Length == totalItemCount + controlItemCount)
                        {
                            isOrdered = true;
                            Ext.Net.Component[] toolbarItems = new Ext.Net.Component[totalItemCount];
                            toolbar.Items.CopyTo(toolbarItems);
                            toolbar.Items.Clear();
                            string controlIndex;
                            int index = 0;
                            int j = 0;
                            for (int i = 0; i < buttons.Length; i++)
                            {
                                controlIndex = buttons[i].ToLower().Trim();

                                if (controlIndex == "0")
                                {
                                    if (btnAdd != null) { toolbar.Items.Insert(j, btnAdd); j++; }
                                }
                                else if (controlIndex == "1")
                                {
                                    if (btnDelete != null) { toolbar.Items.Insert(j, btnDelete); j++; }
                                }
                                else if (controlIndex == "2")
                                {
                                    if (btnToogleSearch != null) { toolbar.Items.Insert(j, btnToogleSearch); j++; }
                                }
                                else
                                {
                                    if (Thesis.Common.Helpers.Ax.TryParse(controlIndex, ref index) && index >= controlItemCount)
                                    {
                                        toolbar.Items.Insert(j, toolbarItems[index - controlItemCount]);
                                        j++;
                                    }
                                }
                            }
                        }
                    }

                    if (!isOrdered)
                    {
                        int index = 0;
                        if (btnAdd != null) { toolbar.Items.Insert(index, btnAdd); index++; }
                        if (btnDelete != null) { toolbar.Items.Insert(index, btnDelete); index++; }
                        if (btnToogleSearch != null) { toolbar.Items.Insert(index, btnToogleSearch); }
                    }

                    #endregion

                    toolbar.Items.Add(new Ext.Net.ToolbarFill());
                    if (btnExport != null) toolbar.Items.Add(btnExport);

                    if (!hasToolBar)
                        TopBar.Add(toolbar);
                }

                #endregion

                #region SelectionModel

                if (!DisableSelectionModel && SelectionModel.Count == 0)
                {
                    Ext.Net.RowSelectionModel rowSelectionModel = new Ext.Net.RowSelectionModel();
                    rowSelectionModel.SingleSelect = SingleSelect;

                    if (btnDelete != null)
                    {
                        rowSelectionModel.Listeners.RowSelect.Handler = "#{" + btnDelete.ID + "}.enable();";
                        rowSelectionModel.Listeners.RowDeselect.Handler = "if (!#{" + this.ID + "}.hasSelection()) {#{" + btnDelete.ID + "}.disable();}";
                    }

                    SelectionModel.Add(rowSelectionModel);
                }

                #endregion

                #region BottomBar

                if (!DisableBottomBar && BottomBar.Count == 0)
                    BottomBar.Add(new Ext.Net.PagingToolbar { PageSize = this.PageSize });

                #endregion

                #region KeyMap

                if (!DisableKeyMap)
                {
                    if (hasDeletePermission && !DisableDelete && !string.IsNullOrEmpty(DeleteUrl))
                    {
                        if (btnDelete != null)
                        {
                            Ext.Net.KeyBinding deleteKey = new Ext.Net.KeyBinding();
                            deleteKey.StopEvent = true;
                            deleteKey.Keys.Add(new Ext.Net.Key { Code = Ext.Net.KeyCode.DELETE });
                            deleteKey.Listeners.Event.Handler = "#{" + btnDelete.ID + "}.fireEvent('click', #{" + btnDelete.ID + "});";

                            KeyMap.Add(deleteKey);
                        }
                        else
                        {
                            Listeners.KeyDown.StopEvent = true;
                            Listeners.KeyDown.Handler = "return e.browserEvent.keyCode == 46 && #{" + this.ID + "}.hasSelection();";

                            DeleteDirectEvent(DirectEvents.KeyDown);
                        }
                    }

                    if (hasAddPermission && !DisableAdd && (DetailPage != null))
                    {
                        Ext.Net.KeyBinding newRecord = new Ext.Net.KeyBinding();
                        newRecord.StopEvent = true;
                        newRecord.Ctrl = true;
                        newRecord.Keys.Add(new Ext.Net.Key { Code = Ext.Net.KeyCode.N });
                        newRecord.Listeners.Event.Handler = DetailPageScript(true);

                        KeyMap.Add(newRecord);
                    }

                    if(DetailPage != null)
                    {
                        Ext.Net.KeyBinding detailKey = new Ext.Net.KeyBinding();
                        detailKey.StopEvent = true;
                        detailKey.Keys.Add(new Ext.Net.Key { Code = Ext.Net.KeyCode.ENTER });
                        detailKey.Listeners.Event.Handler = DetailPageScript(false, "#{" + (this.ID ?? string.Empty) + "}", "Ax.GetSelectedRowIndex(#{" + (this.ID ?? string.Empty) + "})");

                        KeyMap.Add(detailKey);
                    }
                }

                #endregion

                #region View

                if (AutoFillColumns && View.Count == 0)
                    View.Add(new Ext.Net.GridView() { AutoFill=true });

                #endregion

                if (DetailPage != null)
                    Listeners.RowDblClick.Handler = DetailPageScript(false) + Listeners.RowDblClick.Handler;

                LoadMask.ShowMask = !DisableMask;
            }
        }