async void ItemsListView_ItemTapped(ListView sender, Xamarin.Forms.ItemTappedEventArgs e) { ItemDetailEditViewModel model = (ItemDetailEditViewModel)sender.SelectedItem; var REMOVE_OPT = "Remove"; var SHOW_DETAILS_OPT = "View Details"; string SWAP_WITH_PARENT_OPT = null; string MAKE_PRIMARY_LOCATION = null; if (model.Item.Domain.Name.Equals(Constants.locationDomainName)) { MAKE_PRIMARY_LOCATION = "Replace with Selected Location"; } if (model.ItemLocationInformation != null) { if (model.ItemLocationInformation.LocationItem != null) { SWAP_WITH_PARENT_OPT = "Use Parent"; } } var prompt = "Options for " + model.MultiItemUpdateListingDisplayText; var action = await DisplayActionSheet(prompt, "Cancel", REMOVE_OPT, SHOW_DETAILS_OPT, MAKE_PRIMARY_LOCATION, SWAP_WITH_PARENT_OPT); if (action == REMOVE_OPT || action == MAKE_PRIMARY_LOCATION) { viewModel.removeFromUpdatableItemList(model); if (action == MAKE_PRIMARY_LOCATION) { var selectedLocation = viewModel.SelectedLocation; if (selectedLocation != null) { var selectedLocationModel = new ItemDetailEditViewModel(selectedLocation); viewModel.addToUpdatableItemList(selectedLocationModel); } viewModel.SelectedLocation = model.Item; } } else if (action == SHOW_DETAILS_OPT) { var item = model.Item; var viewModel = new ItemDetailViewModel(item); var detailsPage = ItemDetailPage.CreateItemDetailPage(viewModel); await Navigation.PushAsync(detailsPage); } else if (action == SWAP_WITH_PARENT_OPT) { var locInfo = model.ItemLocationInformation; var parent = locInfo.LocationItem; var domainName = parent.Domain.Name; var proceed = true; if (viewModel.StatusMode) { if (!domainName.Equals(Constants.inventoryDomainName)) { await DisplayAlert("Cannot Swap", "Only inventory items have status.", "OK"); proceed = false; } } if (proceed) { viewModel.removeFromUpdatableItemList(model); var newModel = new ItemDetailEditViewModel(parent); viewModel.addToUpdatableItemList(newModel); } } sender.SelectedItem = null; }
public EditItemDetailPage(Item item, ItemDetailPage detailPage) { InitializeComponent(); this.viewModel = new ItemDetailEditViewModel(item); this.detailPage = detailPage; BindingContext = this.viewModel; var domain = item.Domain; addEditBindingToEditItemsStackLayout(domain.ItemIdentifier1Label, "Item.ItemIdentifier1"); if (domain.ItemIdentifier2Label != null && !domain.Name.Equals(Constants.machineDesignDomainName)) { addEditBindingToEditItemsStackLayout(domain.ItemIdentifier2Label, "Item.ItemIdentifier2"); } if (item.Domain.Name.Equals(Constants.inventoryDomainName)) { viewModel.LoadItemStatus(); viewModel.LoadItemLocationInformation(); var propertyApi = CdbApiFactory.Instance.propertyTypeApi; var type = propertyApi.GetInventoryStatusPropertyType(); statusPicker = new Picker { Title = "Item Status", }; foreach (var allowedValue in type.SortedAllowedPropertyValueList) { statusPicker.Items.Add(allowedValue.Value); } var statusString = viewModel.ItemStatusString; if (statusPicker.Items.Contains(statusString)) { statusPicker.SelectedItem = statusString; } addEditBindingToEditItemsStackLayout("QR Id", "QrIdEntry", null, Keyboard.Numeric); addEditBindingToEditItemsStackLayout("Status", null, statusPicker); // Add Location Label itemValueLabel = new Label { FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)) }; itemValueLabel.SetBinding(Label.TextProperty, "ItemLocationInformation.LocationString"); var buttonChangeLocation = new Button { Text = "Change Location" }; var buttonClearLocation = new Button { Text = "Clear Location" }; buttonChangeLocation.Clicked += ChangeLocationEventHandler; buttonClearLocation.Clicked += ClearLocationEventHandler; addEditBindingToEditItemsStackLayout("Location", null, itemValueLabel); EditItemsStackLayout.Children.Add(buttonChangeLocation); EditItemsStackLayout.Children.Add(buttonClearLocation); addEditBindingToEditItemsStackLayout("Location Details ", "ItemLocationInformation.LocationDetails"); } }