private async void btnCreateTemplate_Click(object sender, RoutedEventArgs e) { // Open the NewTemplate Dialog and get the TemplateModel made in there NewTemplateDialog dialog = new NewTemplateDialog(); await dialog.ShowAsync(); //Navigate to the MainPage NavigationService.Navigate(typeof(Views.MainPage)); }
/// <summary> /// Create a new Template by displaying the NewTemplateDialog and add it to the list if the user saves it /// </summary> private async void NewTemplate() { // Open the NewTemplate Dialog and get the TemplateModel made in there NewTemplateDialog dialog = new NewTemplateDialog(); await dialog.ShowAsync(); // Add this model back to the Templates List for use if the dialog wasn't cancelled TemplateModel model = dialog.SavedTemplate; if (model != null) { Templates.Add(model); } }
/// <summary> /// Import from .ics /// </summary> private async void ImportTemplate() { // Get the user to select an .ics-file to import the information from StorageFile ics = null; ImportModel import = null; // Get the ICS to import: try { ics = await GetIcsFile(); } catch { Debug.WriteLine("MainViewModel - ImportTemplate - Failed to obtain .ics-file"); } // Get the info from the .ics import = await GetIcsDetails(ics); // Create a new TemplateModel infused with the imported data if (import != null) { TemplateModel template = new TemplateModel(); template.AppointmentSubject = import.ImportSubject; template.AppointmentDetails = import.ImportDetails; template.AppointmentLocation = import.ImportLocation; // Set the ID to 0 so it'll recognise it and handle it as a Import model template.TemplateId = -1; // Open it in a TemplateEditor Dialog NewTemplateDialog dialog = new NewTemplateDialog(template); await dialog.ShowAsync(); // Add this model back to the Templates List for use if the dialog wasn't cancelled TemplateModel model = dialog.SavedTemplate; if (model != null) { Templates.Add(model); } } else { // #TODO Import unsuccessful, exit the method and display an error to the user } }
/// <summary> /// Edit Template /// </summary> private async void EditTemplate() { TemplateModel originalTemplate = SelectedTemplate; TemplateModel updatedTemplate; // Open the NewTemplate Dialog and get the TemplateModel made in there NewTemplateDialog dialog = new NewTemplateDialog(originalTemplate); await dialog.ShowAsync(); updatedTemplate = dialog.SavedTemplate; // Make sure the template has been updated if (updatedTemplate != null) { // Remove the old template from the list Templates.Remove(originalTemplate); // Add this model back to the Templates List for use Templates.Add(updatedTemplate); } }
public override void Execute(object parameter) { var context = parameter as ContentTreeContext; if (context == null) { AppHost.MessageBox(Resources.NewTemplate_Execute_, Resources.NewTemplate_Execute_Create_New_Template, MessageBoxButton.OK, MessageBoxImage.Information); return; } var item = context.SelectedItems.FirstOrDefault() as ItemTreeViewItem; if (item == null) { AppHost.MessageBox(Resources.NewTemplate_Execute_There_is_no_active_item_, Resources.NewTemplate_Execute_Create_New_Template, MessageBoxButton.OK, MessageBoxImage.Information); return; } // get template name var dialog = new NewTemplateDialog(); dialog.Initialize("New Template", item.ItemUri.DatabaseUri, new[] { IdManager.GetItemId("/sitecore/templates/System/Templates/Standard template") }); if (AppHost.Shell.ShowDialog(dialog) != true) { return; } // create template item var templateName = dialog.ItemName; var templateUri = new ItemUri(item.ItemUri.DatabaseUri, IdManager.GetItemId("/sitecore/templates/System/Templates/Template")); var itemUri = item.ItemUri.Site.DataService.AddFromTemplate(item.ItemUri, templateUri, templateName); if (itemUri == ItemUri.Empty) { AppHost.MessageBox(Resources.NewTemplate_Execute_Failed_to_create_the_template_, Resources.NewTemplate_Execute_Create_New_Template, MessageBoxButton.OK, MessageBoxImage.Information); return; } var baseTemplates = string.Join("|", dialog.SelectedTemplates.Select(i => i.ToString())); if (string.IsNullOrEmpty(baseTemplates)) { baseTemplates = IdManager.GetItemId("/sitecore/templates/System/Templates/Standard template").ToString(); } // set "Base Template" field var baseTemplateField = new Field { Value = baseTemplates, HasValue = true }; baseTemplateField.FieldUris.Add(new FieldUri(new ItemVersionUri(itemUri, LanguageManager.CurrentLanguage, Data.Version.Latest), BaseTemplateFieldId)); var fields = new List <Field> { baseTemplateField }; itemUri.Site.DataService.Save(itemUri.DatabaseName, fields); if (dialog.CreateStandardValues) { CreateStandardValues(itemUri); } // expand tree context.ContentTree.ExpandTo(itemUri); // design template AppHost.Windows.Factory.OpenTemplateDesigner(itemUri); Notifications.RaiseItemAdded(this, new ItemVersionUri(itemUri, LanguageManager.CurrentLanguage, Data.Version.Latest), item.ItemUri); }