Example #1
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            // determine which button was clicked
            Button clickedButton = sender as Button ?? AddButtons[0][0];
            int    listIndex     = buttonList.IndexOf(clickedButton);

            ClientEntity entity = lists[listIndex];

            if (entity is Item)
            {
                var    list   = entity as Item;
                Folder folder = App.ViewModel.Folders.Single(f => f.ID == list.FolderID);
                AddItem(folder, list);
            }
            if (entity is Folder)
            {
                var folder = entity as Folder;
                AddItem(folder, null);
            }

            // increment the SelectedCount
            ListMetadataHelper.IncrementListSelectedCount(App.ViewModel.PhoneClientFolder, entity);

            // if this is a navigation and not an add operation, we need to sync with the service to push the new selected count
            // (do not sync for operations against $ClientSettings)
            //if (String.IsNullOrWhiteSpace(Name.Value))
            //    App.ViewModel.SyncWithService();
        }
Example #2
0
        public List<Item> GetListsOrderedBySelectedCount()
        {
            var lists = ListMetadataHelper.GetListsOrderedBySelectedCount(PhoneClientFolder);

            // if there are no lists with a selected count, create one for each default list
            if (lists.Count == 0)
            {
                // give the task and shopping item lists a count of 2
                var task = GetDefaultList(SystemItemTypes.Task);
                if (task != null)
                {
                    ListMetadataHelper.IncrementListSelectedCount(PhoneClientFolder, task);
                    ListMetadataHelper.IncrementListSelectedCount(PhoneClientFolder, task);
                }
                var grocery = GetDefaultList(SystemItemTypes.Grocery);
                if (grocery != null)
                {
                    ListMetadataHelper.IncrementListSelectedCount(PhoneClientFolder, grocery);
                    ListMetadataHelper.IncrementListSelectedCount(PhoneClientFolder, grocery);
                }

                // give the contact and location lists a count of 1
                var contact = GetDefaultList(SystemItemTypes.Contact);
                if (contact != null)
                    ListMetadataHelper.IncrementListSelectedCount(PhoneClientFolder, contact);
                var location = GetDefaultList(SystemItemTypes.Location);
                if (location != null)
                    ListMetadataHelper.IncrementListSelectedCount(PhoneClientFolder, location);

                // re-retrieve selected count lists
                lists = ListMetadataHelper.GetListsOrderedBySelectedCount(PhoneClientFolder);
            }

            return lists;
        }
Example #3
0
 public ClientEntity GetDefaultList(Guid itemType)
 {
     Item reference = ListMetadataHelper.GetDefaultList(ClientFolder, itemType);
     if (reference == null)
         return Folders.FirstOrDefault(f => f.ItemTypeID == itemType);
     var entityTypeFV = reference.GetFieldValue(FieldNames.EntityType);
     if (entityTypeFV == null || entityTypeFV.Value == null)
         return Folders.FirstOrDefault(f => f.ItemTypeID == itemType);
     var entityRefFV = reference.GetFieldValue(FieldNames.EntityRef);
     if (entityRefFV == null || entityRefFV.Value == null)
         return Folders.FirstOrDefault(f => f.ItemTypeID == itemType);
     string type = entityTypeFV.Value;
     Guid id = new Guid(entityRefFV.Value);
     switch (type)
     {
         case EntityTypes.Folder:
             var folder = Folders.FirstOrDefault(f => f.ID == id);
             if (folder == null)
                 folder = Folders.FirstOrDefault(f => f.ItemTypeID == itemType);
             return folder;
         case EntityTypes.Item:
             var list = Items.FirstOrDefault(i => i.ID == id);
             if (list == null)
                 return Folders.FirstOrDefault(f => f.ItemTypeID == itemType);
             return list;
     }
     return null;
 }
Example #4
0
        private void SortPopup_SortButton_Click(object sender, RoutedEventArgs e)
        {
            Field target = SortPopupListPicker.SelectedItem as Field;

            if (target == null)
            {
                return;
            }

            // store the current listbox and orderby field, and re-render the list
            ListHelper.OrderBy = target.Name;
            ListHelper.RenderList(list);

            // store the sort order
            ListMetadataHelper.StoreListSortOrder(
                App.ViewModel.PhoneClientFolder,
                list.ID == Guid.Empty ? (ClientEntity)folder : (ClientEntity)list,
                target.Name);

            // sync with the service
            // (do not sync for operations against $ClientSettings)
            //App.ViewModel.SyncWithService();

            // close the popup
            sortPopupOpen    = false;
            SortPopup.IsOpen = false;
        }
Example #5
0
        private void SortPopup_RemoveButton_Click(object sender, RoutedEventArgs e)
        {
            // store the current listbox and remove the orderby field, and re-render the list
            ListHelper.OrderBy = null;
            ListHelper.RenderList(list);

            // store the sort order
            ListMetadataHelper.StoreListSortOrder(
                App.ViewModel.PhoneClientFolder,
                list.ID == Guid.Empty ? (ClientEntity)folder : (ClientEntity)list,
                null);

            // sync with the service
            // (do not sync for operations against $ClientSettings)
            //App.ViewModel.SyncWithService();

            // close the popup
            sortPopupOpen    = false;
            SortPopup.IsOpen = false;
        }
Example #6
0
        private void CreateAddButtons()
        {
            if (AddButtons == null)
            {
                AddButtons = new ButtonListElement[3];
            }

            // get all the lists
            var entityRefItems = App.ViewModel.GetListsOrderedBySelectedCount();

            lists = new List <ClientEntity>();
            foreach (var entityRefItem in entityRefItems)
            {
                var entityType = entityRefItem.GetFieldValue(FieldNames.EntityType).Value;
                var entityID   = new Guid(entityRefItem.GetFieldValue(FieldNames.EntityRef).Value);
                if (entityType == typeof(Folder).Name && App.ViewModel.Folders.Any(f => f.ID == entityID))
                {
                    lists.Add(App.ViewModel.Folders.Single(f => f.ID == entityID));
                }
                if (entityType == typeof(Item).Name && App.ViewModel.Items.Any(i => i.ID == entityID))
                {
                    lists.Add(App.ViewModel.Items.Single(i => i.ID == entityID));
                }
            }

            // create a list of buttons - one for each list
            buttonList = (from it in lists
                          select new Button()
            {
                Background = "Images/darkgreybutton.png",
                Caption = it.Name,
                Clicked = AddButton_Click
            }).ToList();

            // clear the button rows
            for (int i = 0; i < AddButtons.Length; i++)
            {
                AddButtons[i] = null;
            }

            // assemble the buttons into rows (maximum of six buttons and two rows)
            // if there are three or less buttons, one row
            // otherwise distribute evenly across two rows
            int count = Math.Min(buttonList.Count, MaxLists);
            int firstrow = count, secondrow = 0, addButtonsRow = 0;

            if (count > MaxLists / 2)
            {
                firstrow  = count / 2;
                secondrow = count - firstrow;
            }
            if (firstrow > 0)
            {
                AddButtons[addButtonsRow++] = new ButtonListElement()
                {
                    buttonList.Take(firstrow)
                };
            }
            if (secondrow > 0)
            {
                AddButtons[addButtonsRow++] = new ButtonListElement()
                {
                    buttonList.Skip(firstrow).Take(secondrow)
                };
            }

            // create a last "row" of buttons containing only one "More..." button which will bring up the folder/list page
            AddButtons[addButtonsRow] = new ButtonListElement()
            {
                new Button()
                {
                    Background = "Images/darkgreybutton.png",
                    Caption    = "More...",
                    Clicked    = (s, e) =>
                    {
                        // assemble a page which contains a hierarchy of every folder and list, grouped by folder
                        var title = String.IsNullOrEmpty(Name.Value) ? "Navigate to:" : "Add " + Name.Value + " to:";
                        ListsRootElement = new ThemedRootElement(title)
                        {
                            from f in App.ViewModel.Folders
                            orderby f.Name ascending
                                 select new Section()
                            {
                                new StyledStringElement(f.Name, delegate
                                {
                                    AddItem(f, null);
                                    // increment the selected count for this folder and sync if this isn't an actual Add
                                    ListMetadataHelper.IncrementListSelectedCount(App.ViewModel.PhoneClientFolder, f);
                                    // (do not sync for operations against $ClientSettings)
                                    //if (String.IsNullOrWhiteSpace(Name.Value))
                                    //    App.ViewModel.SyncWithService();
                                })
                                {
                                    Image = UIImageCache.GetUIImage("Images/appbar.folder.rest.png")
                                },
                                from li in f.Items
                                where li.IsList == true && li.ItemTypeID != SystemItemTypes.Reference
                                orderby li.Name ascending
                                select(Element) new StyledStringElement("        " + li.Name, delegate
                                {
                                    AddItem(f, li);
                                    // increment the selected count for this list and sync if this isn't an actual Add
                                    ListMetadataHelper.IncrementListSelectedCount(App.ViewModel.PhoneClientFolder, li);
                                    // (do not sync for operations against $ClientSettings)
                                    //if (String.IsNullOrWhiteSpace(Name.Value))
                                    //    App.ViewModel.SyncWithService();
                                })
                                {
                                    Image = UIImageCache.GetUIImage("Images/179-notepad.png")
                                }
                            }
                        };
                        var dvc = new DialogViewController(ListsRootElement, true);
                        dvc.TableView.BackgroundColor      = UIColorHelper.FromString(App.ViewModel.Theme.PageBackground);
                        dvc.NavigationItem.HidesBackButton = false;
                        dialogViewController.NavigationController.PushViewController(dvc, true);
                    }
                }
            };
        }
Example #7
0
        // When page is navigated to set data context to selected item in itemType
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // trace data
            TraceHelper.AddMessage("ListPage: OnNavigatedTo");

            // handle list picker navigation cases
            if (sortPopupOpen == true)
            {
                SortPopup.IsOpen = true;
                return;
            }
            if (importPopupOpen == true)
            {
                ImportListPopup.IsOpen = true;
                return;
            }

            string IDString = "";
            Guid   id;

            // get the type of list to display
            if (NavigationContext.QueryString.TryGetValue("type", out typeString) == false)
            {
                // trace page navigation
                TraceHelper.StartMessage("ListPage: Navigate back");

                // navigate back
                NavigateBack();
                return;
            }

            // get the ID of the object to display
            if (NavigationContext.QueryString.TryGetValue("ID", out IDString) == false)
            {
                // trace page navigation
                TraceHelper.StartMessage("ListPage: Navigate back");

                // navigate back
                NavigateBack();
                return;
            }

            // get the ID
            id = new Guid(IDString);

            switch (typeString)
            {
            case "Folder":
                // get the folder and make it the datacontext
                try
                {
                    folder = App.ViewModel.LoadFolder(id);

                    // if the load failed, this folder has been deleted
                    if (folder == null)
                    {
                        // the folder isn't found - this can happen when the folder we were just
                        // editing was removed in FolderEditor, which then goes back to ListPage.
                        // this will send us back to the MainPage which is appropriate.

                        // trace page navigation
                        TraceHelper.StartMessage("ListPage: Navigate back");

                        // navigate back
                        NavigateBack();
                        return;
                    }

                    // get the ID of the list to display
                    if (NavigationContext.QueryString.TryGetValue("ParentID", out IDString) == false)
                    {
                        // trace page navigation
                        TraceHelper.StartMessage("ListPage: Navigate back");

                        // navigate back
                        NavigateBack();
                        return;
                    }

                    // get the ID
                    id = new Guid(IDString);

                    // get the current list name
                    string listName = null;
                    Guid?  listID   = null;
                    Guid   itemTypeID;
                    if (id == Guid.Empty)
                    {
                        listName   = folder.Name;
                        itemTypeID = folder.ItemTypeID;
                    }
                    else
                    {
                        var item = folder.Items.Single(i => i.ID == id);
                        listName   = item.Name;
                        listID     = (Guid?)id;
                        itemTypeID = item.ItemTypeID;

                        // change the "edit folder" appbar button title to "edit list"
                        ApplicationBarIconButton button = null;
                        for (int i = 0; i < ApplicationBar.Buttons.Count; i++)
                        {
                            button = (ApplicationBarIconButton)ApplicationBar.Buttons[i];
                            if (button.Text.StartsWith("edit", StringComparison.InvariantCultureIgnoreCase))
                            {
                                break;
                            }
                        }
                        if (button.Text.StartsWith("edit", StringComparison.InvariantCultureIgnoreCase))
                        {
                            button.Text = "edit list";
                        }
                    }

                    // construct a synthetic item that represents the list of items for which the
                    // ParentID is the parent.  this also works for the root list in a folder, which
                    // is represented with a ParentID of Guid.Empty.
                    list = new Item()
                    {
                        ID         = id,
                        Name       = listName,
                        FolderID   = folder.ID,
                        IsList     = true,
                        ItemTypeID = itemTypeID,
                        Items      = folder.Items.Where(i => i.ParentID == listID).ToObservableCollection()
                    };
                }
                catch (Exception ex)
                {
                    // the folder isn't found - this can happen when the folder we were just
                    // editing was removed in FolderEditor, which then goes back to ListPage.
                    // this will send us back to the MainPage which is appropriate.

                    // trace page navigation
                    TraceHelper.StartMessage(String.Format("ListPage: Navigate back (exception: {0})", ex.Message));

                    // navigate back
                    NavigateBack();
                    return;
                }
                break;

            case "Tag":
                // create a filter
                try
                {
                    tag = App.ViewModel.Tags.Single(t => t.ID == id);

                    // construct a synthetic item that represents the list of items which
                    // have this tag.
                    list = new Item()
                    {
                        ID    = Guid.Empty,
                        Name  = String.Format("items with {0} tag", tag.Name),
                        Items = App.ViewModel.Items.Where(t => t.ItemTags.Any(tg => tg.TagID == tag.ID)).ToObservableCollection()
                    };
                }
                catch (Exception)
                {
                    // the tag isn't found - this can happen when the tag we were just
                    // editing was removed in TagEditor, which then goes back to ListPage.
                    // this will send us back to the MainPage which is appropriate.

                    // trace page navigation
                    TraceHelper.StartMessage("ListPage: Navigate back");

                    // navigate back
                    NavigateBack();
                    return;
                }
                break;

            default:
                // trace page navigation
                TraceHelper.StartMessage("ListPage: Navigate back");

                // navigate back
                NavigateBack();
                return;
            }

            // set datacontext
            ListGrid.DataContext = list;

            // create the ListHelper
            ListHelper = new ListHelper(
                new RoutedEventHandler(CompleteCheckbox_Click),
                new RoutedEventHandler(Tag_HyperlinkButton_Click));

            // store the current listbox and ordering
            ListHelper.ListBox = ItemsListBox;
            ListHelper.OrderBy = ListMetadataHelper.GetListSortOrder(
                App.ViewModel.PhoneClientFolder,
                id == Guid.Empty ? (ClientEntity)folder : (ClientEntity)list);

            // trace data
            TraceHelper.AddMessage("Exiting ListPage OnNavigatedTo");
        }