/// <summary> /// Called when the user changes the selected items in the table. /// </summary> protected override void OnSelectedItemsChanged() { base.OnSelectedItemsChanged(); if (this.SelectedItems.Count == 1) { var selectedItem = this.SelectedItems[0]; _copyCannedTextToClipboardAction.Enabled = true; this.ActionModel.Add.Enabled = HasPersonalAdminAuthority || HasGroupAdminAuthority; this.ActionModel.Delete.Enabled = _duplicateCannedTextAction.Enabled = selectedItem.IsPersonal && HasPersonalAdminAuthority || selectedItem.IsGroup && HasGroupAdminAuthority; } else { _duplicateCannedTextAction.Enabled = false; _copyCannedTextToClipboardAction.Enabled = false; } _editCannedTextCategoryAction.Enabled = this.SelectedItems.Count > 1; // The detail is only loaded whenever a copy/drag is performed // Set this to null, so the view doesn't get wrong text data. _selectedCannedTextDetail = null; NotifyAllPropertiesChanged(); }
public string GetFullCannedText() { if (this.SelectedItems.Count != 1) { return(string.Empty); } // if the detail object is not null, it means the selection havn't changed // no need to hit the server, return the text now if (_selectedCannedTextDetail != null) { return(_selectedCannedTextDetail.Text); } var summary = CollectionUtils.FirstElement(this.SelectedItems); try { Platform.GetService <ICannedTextService>( service => { var response = service.LoadCannedTextForEdit(new LoadCannedTextForEditRequest(summary.CannedTextRef)); _selectedCannedTextDetail = response.CannedTextDetail; }); } catch (Exception e) { ExceptionHandler.Report(e, this.Host.DesktopWindow); } return(_selectedCannedTextDetail.Text); }
public CannedText CreateCannedText(CannedTextDetail detail, Staff owner, IPersistenceContext context) { CannedText newCannedText = new CannedText(); UpdateCannedText(newCannedText, detail, owner, context); return(newCannedText); }
public void UpdateCannedText(CannedText cannedText, CannedTextDetail detail, Staff owner, IPersistenceContext context) { cannedText.Name = detail.Name; cannedText.Category = detail.Category; cannedText.Staff = detail.IsPersonal ? owner : null; cannedText.StaffGroup = detail.IsGroup ? context.Load <StaffGroup>(detail.StaffGroup.StaffGroupRef, EntityLoadFlags.Proxy) : null; cannedText.Text = detail.Text; }
private static void CheckCannedTextWriteAccess(CannedTextDetail cannedText) { CheckCannedTextWriteAccess(cannedText.IsPersonal); }
public override void Start() { // Insert a blank choice as the first element _categoryChoices.Insert(0, ""); Platform.GetService <ICannedTextService>( service => { var formDataResponse = service.GetCannedTextEditFormData(new GetCannedTextEditFormDataRequest()); _staffGroupChoices = formDataResponse.StaffGroups; if (_isNew && _isDuplicate == false) { _cannedTextDetail = new CannedTextDetail(); _isEditingPersonal = HasPersonalAdminAuthority; } else { var response = service.LoadCannedTextForEdit(new LoadCannedTextForEditRequest(_cannedTextRef)); _cannedTextDetail = response.CannedTextDetail; _isEditingPersonal = _cannedTextDetail.IsPersonal; if (_isDuplicate) { this.Name = ""; } } }); // The selected staff groups should only contain entries in the selected group choices if (_cannedTextDetail.StaffGroup == null) { _cannedTextDetail.StaffGroup = CollectionUtils.FirstElement(_staffGroupChoices); } else { _cannedTextDetail.StaffGroup = CollectionUtils.SelectFirst(_staffGroupChoices, choice => _cannedTextDetail.StaffGroup.StaffGroupRef.Equals(choice.StaffGroupRef, true)); } // add validation rule to ensure the group must be populated when editing group this.Validation.Add(new ValidationRule("StaffGroup", delegate { var ok = this.IsEditingPersonal || this.IsEditingGroup && this.StaffGroup != null; return(new ValidationResult(ok, Desktop.SR.MessageValueRequired)); })); if (CannedTextSettings.Default.RestrictNameToAlphaChars) { // add validation rule to ensure the name does not contain invalid characters this.Validation.Add(new ValidationRule("Name", delegate { if (string.IsNullOrEmpty(this.Name)) { return(new ValidationResult(true, "")); } // only allow alphabets and space var ok = Regex.IsMatch(this.Name, @"^[A-Za-z ]+$"); return(new ValidationResult(ok, SR.MessageCannedTextNameCanOnlyContainAlphaChars)); })); } if (CannedTextSettings.Default.RestrictFieldsToAlphaChars) { // add validation rule to ensure the name field in the text does not contain invalid characters this.Validation.Add(new ValidationRule("Text", delegate { if (string.IsNullOrEmpty(this.Text)) { return(new ValidationResult(true, "")); } // look for none alphabets and space within the named field square brackets // Patterns explaination // \[ - match beginning bracket // [^\[\]]* - match any number of non brackets characters // [^a-zA-Z ] - match at least one alphabets and space characters // [^\[\]]* - match any number of non brackets characters // \] - match ending bracket var match = Regex.Match(this.Text, @"\[[^\[\]]*[^a-zA-Z ][^\[\]]*\]"); var message = match.Success ? string.Format(SR.MessageCannedTextNameFieldCanOnlyContainAlphaChars, match.Value) : null; return(new ValidationResult(!match.Success, message)); })); } base.Start(); }