protected override void OnFormBound()
 {
     base.OnFormBound();
     _pickListView = GetPickListView();
     _defaultItem  = GetDefaultItem(_pickListView);
     LoadGrid();
 }
    private void SaveItem()
    {
        _pickListView        = getPickListHeader(null);
        _isPickListLocalized = !string.IsNullOrWhiteSpace(_pickListView.DefaultLanguage);
        if (string.IsNullOrEmpty(txtItemText.Text))
        {
            throw new ValidationException(GetLocalResourceObject("error_InvalidItemName").ToString());
        }
        if (_isPickListLocalized && string.IsNullOrEmpty(txtCode.Text))
        {
            throw new ValidationException(GetLocalResourceObject("error_InvalidItemCode").ToString());
        }
        var keyChanged = false;

        if (_pickListItemView == null && !string.IsNullOrEmpty(hdPickListItemId.Value) && !string.IsNullOrEmpty(hdPickListId.Value))
        {
            _pickListItemView = EntityFactory.GetByCompositeId(typeof(IPickListItemView), new[] { "PickListItemId", "PickListId" }, new object[] { hdPickListItemId.Value, hdPickListId.Value }) as IPickListItemView;
        }
        if (_pickListItemView != null)
        {
            keyChanged = !string.Equals(_pickListItemView.Code, txtCode.Text) || !string.Equals(_pickListItemView.LanguageCode, cboLanguage.SelectedValue);
        }
        PickListHelper.DialogTypes dtMode = PickListHelper.StringToDialogTypes(hdMode.Value);
        if (keyChanged || (string.IsNullOrEmpty(hdPickListItemId.Value) && dtMode == PickListHelper.DialogTypes.Add) || dtMode == PickListHelper.DialogTypes.Localize)
        {
            var      order = Convert.ToInt32(txtOrder.Text);
            PickList pl    = PickList.AddNewPickListItem(hdPickListId.Value, txtItemText.Text, txtCode.Text, txtFilter.Text, cboLanguage.SelectedValue, order, string.Empty);
            if (chkIsDefaultItem.Checked)
            {
                PickList.SetAsDefaultItemCode(hdPickListId.Value, pl.ItemId);
            }
        }
        else
        {
            PickList pl = PickList.GetPickListItemById(hdPickListId.Value, hdPickListItemId.Value);
            pl.Shorttext = txtCode.Text;
            pl.Text      = txtItemText.Text;
            var orderValue = Convert.ToInt32(txtOrder.Text);
            pl.Id           = orderValue;
            pl.Filter       = txtFilter.Text;
            pl.LanguageCode = cboLanguage.SelectedValue;
            PickList.SavePickListItem(pl);

            if (chkIsDefaultItem.Checked && string.IsNullOrEmpty(hdIsDefault.Value))
            {
                PickList.SetAsDefaultItemCode(hdPickListId.Value, pl.ItemId);
            }
            if (!chkIsDefaultItem.Checked && !string.IsNullOrEmpty(hdIsDefault.Value))
            {
                PickList.SetAsDefaultItemCode(hdPickListId.Value, string.Empty);
            }
        }
        var picklistService = ApplicationContext.Current.Services.Get <IPickListService>(true);

        picklistService.ClearPickListCache();
        var refresher = PageWorkItem.Services.Get <IPanelRefreshService>();

        refresher.RefreshAll();
    }
 private IPickListItemView GetDefaultItem(IPickListView picklistView)
 {
     if ((picklistView.DefaultIndex.HasValue) && (picklistView.DefaultIndex.Value >= 0))
     {
         PickList plItem = PickList.GetDefaultItem(picklistView.Id.ToString());
         if (plItem != null)
         {
             string[]          IdNames = new string[] { "PickListId", "PickListItemId" };
             object[]          ids     = new object[] { plItem.PickListId, plItem.ItemId };
             IPickListItemView piv     = EntityFactory.GetByCompositeId(typeof(IPickListItemView), IdNames, ids) as IPickListItemView;
             return(piv);
         }
     }
     return(null);
 }
    protected override void OnFormBound()
    {
        base.OnFormBound();
        if (DialogService.DialogParameters.Count > 0)
        {
            object mode;
            hdMode.Value = string.Empty;
            if (DialogService.DialogParameters.TryGetValue("MODE", out mode))
            {
                _mode        = mode.ToString();
                hdMode.Value = _mode;
            }

            object pickListId;
            hdPickListId.Value = string.Empty;

            DialogService.DialogParameters.TryGetValue("PickListId", out pickListId);
            _pickListView        = getPickListHeader((string)pickListId);
            hdPickListId.Value   = _pickListView.Id.ToString();
            _isPickListLocalized = !string.IsNullOrWhiteSpace(_pickListView.DefaultLanguage);
            string defaultLanguage = Request.Cookies["SLXLanguageSetting"].Value ?? _pickListView.DefaultLanguage ?? "en";
            defaultLanguage = defaultLanguage.ToLowerInvariant();
            cboLanguage.Items.Clear();
            List <EnabledLanguage> cultures = PickListHelper.GetLanguageList <EnabledLanguage>(PickListHelper.LanguageListTypes.Cultures);
            cultures.ForEach(ci => cboLanguage.Items.Add(new ListItem(text: ci.DisplayText, value: ci.CultureCode.ToLowerInvariant())));
            EnabledLanguage lostLanguage = string.IsNullOrWhiteSpace(defaultLanguage) ? null : RegionList.Cultures.Find(x => x.CultureCode.Equals(defaultLanguage, StringComparison.OrdinalIgnoreCase));
            if (lostLanguage == null)
            {
                cboLanguage.Items.Add(new ListItem(defaultLanguage, defaultLanguage));
            }
            if (!_isPickListLocalized)
            {
                cboLanguage.Items.Insert(0,
                                         new ListItem(string.Empty, null)
                                         );
            }
            object pickListItemId;
            hdPickListItemId.Value = string.Empty;
            if (DialogService.DialogParameters.TryGetValue("PickListItemId", out pickListItemId))
            {
                var idNames = new[] { "PickListItemId", "PickListId" };
                var ids     = new[] { pickListItemId, pickListId };
                _pickListItemView      = EntityFactory.GetByCompositeId(typeof(IPickListItemView), idNames, ids) as IPickListItemView;
                hdPickListItemId.Value = pickListItemId.ToString();
            }
        }
        LoadView();
    }
 private void SetDefaultFlag()
 {
     chkIsDefaultItem.Checked = false;
     hdIsDefault.Value        = string.Empty;
     if (_pickListView != null)
     {
         IPickListItemView defaultItem = GetDefaultItem(_pickListView);
         if (defaultItem != null)
         {
             if (defaultItem.PickListItemId == _pickListItemView.PickListItemId)
             {
                 chkIsDefaultItem.Checked = true;
                 hdIsDefault.Value        = "True";
             }
         }
     }
 }
 private void Hydrate()
 {
     _pickListView = GetPickListView();
     if (_pickListView != null)
     {
         _defaultItem = GetDefaultItem(_pickListView);
         cboViewedLanguage.Items.Clear();
         cboViewedLanguage.Items.Insert(0, new ListItem(GetLocalResourceObject("AllItems").ToString(), AllItems));
         IList <string> codes = PickList.GetLanguageCodesInUse(true);
         foreach (var code in codes)
         {
             if (!string.IsNullOrWhiteSpace(code))
             {
                 cboViewedLanguage.Items.Add(new ListItem(code, code));
             }
         }
         cboViewedLanguage.SelectedValue = (string)ViewState["PickListItemLanguageFilter"] ?? AllItems;
     }
 }
    private void AppendJavaScriptOnClickDeletionCode(GridViewRow row, List <IPickListItemView> rowData)
    {
        if (row.RowType == DataControlRowType.DataRow)
        {
            // Get the LinkButton control for the Delete
            if (DeleteColumnIndex >= 0 && DeleteColumnIndex < row.Cells.Count)
            {
                string pickListItemId = null;
                if (rowData != null)
                {
                    IPickListItemView pklivRow = rowData[row.RowIndex];
                    if (pklivRow != null)
                    {
                        pickListItemId = pklivRow.PickListItemId;
                    }
                }

                var       dialogBody = GenerateRowApporiateDeletionWarning(pickListItemId);
                TableCell cell       = row.Cells[DeleteColumnIndex];
                foreach (Control c in cell.Controls)
                {
                    var btn = c as LinkButton;
                    if (btn != null)
                    {
                        var script = new StringBuilder();
                        script.AppendLine(" javascript: return require(['dojo/topic'], function(topic, ) {return function confirmation() {");
                        script.AppendLine(" var answer = confirm('" + dialogBody + "');");
                        script.AppendLine(" if (answer) {");
                        script.AppendLine(" (removePickListCache())()");
                        if (_pickListView != null && !string.IsNullOrWhiteSpace((string)_pickListView.Id))
                        {
                            script.AppendLine("topic.publish('/group/context/changed/picklistview/item/removed', { toEntityId: '" + _pickListView.Id + "', updateTest: 1 });");
                        }
                        script.AppendLine(" }");
                        script.AppendLine(" return answer;");
                        script.AppendLine(" }(); });");
                        btn.Attributes.Add("onclick", script.ToString());
                    }
                }
                grdPicklistItems.Columns[LocalizeColumnIndex + 1].Visible = _pickListView != null && !string.IsNullOrWhiteSpace(_pickListView.DefaultLanguage);
            }
        }
    }
 private void SetDefaultFlag()
 {
     chkIsDefaultItem.Checked = false;
     chkIsDefaultItem.Enabled = _inDefaultLanguage;
     hdIsDefault.Value        = string.Empty;
     if (_pickListView != null)
     {
         IPickListItemView defaultItem = GetDefaultItem(_pickListView);
         if (defaultItem != null)
         {
             foreach (string str in _pickListItemView.Ids)
             {
                 if (defaultItem.PickListItemId == str)
                 {
                     chkIsDefaultItem.Checked = true;
                     hdIsDefault.Value        = "True";
                 }
             }
         }
     }
 }
    protected override void OnFormBound()
    {
        base.OnFormBound();

        if (DialogService.DialogParameters.Count > 0)
        {
            object mode;
            hdMode.Value = string.Empty;
            if (DialogService.DialogParameters.TryGetValue("MODE", out mode))
            {
                _mode        = mode.ToString();
                hdMode.Value = _mode;
            }


            object pickListId;
            hdPickListId.Value = string.Empty;
            if (DialogService.DialogParameters.TryGetValue("PickListId", out pickListId))
            {
                this._pickListView = Sage.Platform.EntityFactory.GetById <IPickListView>(pickListId);
                hdPickListId.Value = pickListId.ToString();
            }
            else
            {
                this._pickListView = GetParentEntity() as IPickListView;
                hdPickListId.Value = this._pickListView.Id.ToString();
            }
            object pickListItemId;
            hdPickListItemId.Value = string.Empty;
            if (DialogService.DialogParameters.TryGetValue("PickListItemId", out pickListItemId))
            {
                string[] IdNames = new string[] { "PickListItemId", "PickListId" };
                object[] Ids     = new object[] { pickListItemId, pickListId };
                this._pickListItemView = Sage.Platform.EntityFactory.GetByCompositeId(typeof(IPickListItemView), IdNames, Ids) as IPickListItemView;
                hdPickListItemId.Value = pickListItemId.ToString();
            }
        }

        LoadView();
    }
    protected override void OnFormBound()
    {
        base.OnFormBound();
        if (DialogService.DialogParameters.Count > 0)
        {
            object mode;
            hdMode.Value = string.Empty;
            if (DialogService.DialogParameters.TryGetValue("MODE", out mode))
            {
                _mode = mode.ToString();
                hdMode.Value = _mode;
            }

            object pickListId;
            hdPickListId.Value = string.Empty;
            if (DialogService.DialogParameters.TryGetValue("PickListId", out pickListId))
            {
                _pickListView = EntityFactory.GetById<IPickListView>(pickListId);
                hdPickListId.Value = pickListId.ToString();
            }
            else
            {
                _pickListView = GetParentEntity() as IPickListView;
                hdPickListId.Value = _pickListView.Id.ToString();
            }
            object pickListItemId;
            hdPickListItemId.Value = string.Empty;
            if (DialogService.DialogParameters.TryGetValue("PickListItemId", out pickListItemId))
            {

                string[] IdNames = new string[] {"PickListItemId","PickListId"};
                object[] Ids = new object[] { pickListItemId, pickListId};
                _pickListItemView = EntityFactory.GetByCompositeId(typeof(IPickListItemView), IdNames, Ids) as IPickListItemView;
                hdPickListItemId.Value = pickListItemId.ToString();
            }
        }
        LoadView();
    }
 protected override void OnFormBound()
 {
     base.OnFormBound();
     _pickListView = GetPickListView();
     _defaultItem = GetDefaultItem(_pickListView);
     LoadGrid();
 }