Ejemplo n.º 1
0
 public ListViewController(UIViewController parent, Folder f, Guid? currentID)
     : base()
 {
     folder = f;
     listID = (currentID == Guid.Empty) ? (Guid?) null : (Guid?) currentID;
     parentController = parent;
 }
Ejemplo n.º 2
0
 public static void IncrementListSelectedCount(Folder phoneClient, ClientEntity list)
 {
     // get, increment, and store the selected count for a list
     string countString = GetListMetadataValue(phoneClient, list, ExtendedFieldNames.SelectedCount);
     int count = Convert.ToInt32(countString);
     count++;
     countString = count.ToString();
     StoreListMetadataValue(phoneClient, list, ExtendedFieldNames.SelectedCount, countString);
 }
Ejemplo n.º 3
0
        public static Item GetDefaultList(Folder client, Guid itemType)
        {
            var defaultLists = GetDefaultListsList(client);
            if (defaultLists == null)
                return null;

            return client.Items.FirstOrDefault(
                    i => i.ParentID == defaultLists.ID &&
                    i.FieldValues.Any(f => f.FieldName == FieldNames.Value && f.Value == itemType.ToString()));
        }
Ejemplo n.º 4
0
 public FolderEditor(UINavigationController c, Folder f)
 {
     // trace event
     TraceHelper.AddMessage("FolderEditor: constructor");
     controller = c;
     folder = f;
     if (f == null)
         folderCopy = new Folder();
     else
         folderCopy = new Folder(folder);
 }
Ejemplo n.º 5
0
        public static List<Item> GetListsOrderedBySelectedCount(Folder phoneClient)
        {
            var metadataList = GetListMetadataList(phoneClient);
            var selectedCountLists = phoneClient.Items.Where(i =>
                i.ParentID == metadataList.ID &&
                i.FieldValues.Any(fv => fv.FieldName == ExtendedFieldNames.SelectedCount)).ToList();

            var orderedLists = new List<SelectedCount>();
            foreach (var l in selectedCountLists)
                orderedLists.Add(new SelectedCount() { EntityRefItem = l, Count = Convert.ToInt32(l.GetFieldValue(ExtendedFieldNames.SelectedCount).Value) });

            // return the ordered lists
            return orderedLists.OrderByDescending(sc => sc.Count).ThenBy(sc => sc.EntityRefItem.Name).Select(sc => sc.EntityRefItem).ToList();
        }
Ejemplo n.º 6
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // trace event
            TraceHelper.AddMessage("FolderEditor: OnNavigatedTo");

            if (e.NavigationMode == NavigationMode.Back)
                return;

            string folderIDString = "";

            if (NavigationContext.QueryString.TryGetValue("ID", out folderIDString))
            {
                if (folderIDString == "new")
                {
                    // new folder
                    folderCopy = new Folder();
                    TitlePanel.DataContext = folderCopy;
                }
                else
                {
                    Guid folderID = new Guid(folderIDString);
                    folder = App.ViewModel.Folders.Single<Folder>(tl => tl.ID == folderID);

                    // make a deep copy of the item for local binding
                    folderCopy = new Folder(folder);
                    TitlePanel.DataContext = folderCopy;

                    // add the delete button to the ApplicationBar
                    var button = new ApplicationBarIconButton() { Text = "Delete", IconUri = new Uri("/Images/appbar.delete.rest.png", UriKind.Relative) };
                    button.Click += new EventHandler(DeleteButton_Click);

                    // insert after the save button but before the cancel button
                    ApplicationBar.Buttons.Add(button);
                }

                // set up the item type listpicker
                var itemTypes = App.ViewModel.ItemTypes.Where(i => i.UserID != SystemUsers.System).OrderBy(i => i.Name).ToList();
                ItemTypePicker.ItemsSource = itemTypes;
                ItemTypePicker.DisplayMemberPath = "Name";
                ItemType thisItemType = itemTypes.FirstOrDefault(i => i.ID == folderCopy.ItemTypeID);
                ItemTypePicker.SelectedIndex = Math.Max(itemTypes.IndexOf(thisItemType), 0);
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Resolve Item conflicts between a local and remote Folder
 /// </summary>
 /// <param name="localFolder">Local item itemType</param>
 /// <param name="remoteFolder">Item itemType retrieved from the data service</param>
 private static void ResolveItems(Folder localFolder, Folder remoteFolder)
 {
     foreach (Item localItem in localFolder.Items)
     {
         bool foundItem = false;
         foreach (Item remoteItem in remoteFolder.Items)
         {
             if (localItem.ID == remoteItem.ID)
             {
                 foundItem = true;
                 break;
             }
         }
         if (foundItem == false)
         {
             remoteFolder.Items.Add(localItem);
         }
     }
 }
Ejemplo n.º 8
0
 public ListEditor(UINavigationController c, Folder f, Item l, Guid? parentID)
 {
     // trace event
     TraceHelper.AddMessage("ListEditor: constructor");
     controller = c;
     list = l;
     if (l == null)
     {
         // new list
         DateTime now = DateTime.UtcNow;
         listCopy = new Item()
         {
             FolderID = f != null ? f.ID : Guid.Empty,
             ParentID = parentID ?? Guid.Empty,
             IsList = true,
             ItemTypeID = f != null ? f.ItemTypeID : SystemItemTypes.Task,
             Created = now,
             LastModified = now
         };
     }
     else
         listCopy = new Item(list);
 }
Ejemplo n.º 9
0
        public static string GetListMetadataValue(Folder phoneClient, ClientEntity list, string fieldName)
        {
            if (phoneClient == null)
                return null;

            var listsMetadata = GetListMetadataList(phoneClient);
            var listID = list.ID.ToString();
            string value = null;
            if (phoneClient.Items.Any(i =>
                i.ParentID == listsMetadata.ID &&
                i.FieldValues.Any(fv => fv.FieldName == FieldNames.EntityRef && fv.Value == listID)))
            {
                var metadataItem = phoneClient.Items.Single(i =>
                    i.ParentID == listsMetadata.ID &&
                    i.FieldValues.Any(fv => fv.FieldName == FieldNames.EntityRef && fv.Value == listID));
                if (metadataItem.FieldValues.Any(fv => fv.FieldName == fieldName))
                {
                    var fieldValue = metadataItem.FieldValues.Single(fv => fv.FieldName == fieldName);
                    value = (fieldValue != null) ? fieldValue.Value : null;
                }
            }
            return value;
        }
Ejemplo n.º 10
0
        public static void StorePhoneSetting(Folder phoneClient, string setting, string value)
        {
            if (phoneClient == null)
                return;

            var phoneSettingsItem = GetPhoneSettingsItem(phoneClient);
            var settings = phoneSettingsItem.GetFieldValue(FieldNames.Value, true);
            JObject jsonSettings = null;
            if (settings != null && !String.IsNullOrEmpty(settings.Value))
                jsonSettings = JObject.Parse(settings.Value);
            else
                jsonSettings = new JObject();
            jsonSettings[setting] = value;
            settings.Value = jsonSettings.ToString();

            // store the phone client folder
            StorageHelper.WritePhoneClient(phoneClient);
        }
Ejemplo n.º 11
0
 public static string GetListSortOrder(Folder phoneClient, ClientEntity list)
 {
     return GetListMetadataValue(phoneClient, list, ExtendedFieldNames.SortBy);
 }
Ejemplo n.º 12
0
        private void AddItem(Folder folder, Item list)
        {
            string name = Name.Value;

                // don't add empty items - instead, navigate to the list
            if (name == null || name == "")
            {
                UIViewController nextController = new ListViewController(this, folder, list != null ? list.ID : Guid.Empty);
                TraceHelper.StartMessage("AddPage: Navigate to List");
                this.PushViewController(nextController, true);
                return;
            }

            Guid itemTypeID;
            Guid parentID;
            if (list == null)
            {
                itemTypeID = folder.ItemTypeID;
                parentID = Guid.Empty;
            }
            else
            {
                itemTypeID = list.ItemTypeID;
                parentID = list.ID;
            }

            // get a reference to the item type
            ItemType itemType = App.ViewModel.ItemTypes.Single(it => it.ID == itemTypeID);

            // special case grocery items - split the name by comma and add a new grocery item for each string
            if (itemTypeID == SystemItemTypes.Grocery)
                foreach (var si in name.Split(','))
                    CreateItem(si.Trim(), folder, itemType, parentID);
            else
                CreateItem(name, folder, itemType, parentID);

            // save the changes to local storage
            StorageHelper.WriteFolder(folder);

            // trigger a sync with the Service
            App.ViewModel.SyncWithService();

            // reset the name field to make it easy to add the next one
            Name.Value = "";

            this.PopViewControllerAnimated(true);
        }
Ejemplo n.º 13
0
        // helper for adding list item to either $Client or $PhoneClient folder
        private static Item GetOrCreateList(Folder folder, string name, Guid itemType)
        {
            if (folder == null)
                return null;

            // get the list item
            Item listItem = null;
            if (folder.Items.Any(i => i.Name == name && i.ParentID == null))
                listItem = folder.Items.First(i => i.Name == name && i.ParentID == null);
            else
            {
                DateTime now = DateTime.UtcNow;
                listItem = new Item()
                {
                    Name = SystemEntities.ListMetadata,
                    FolderID = folder.ID,
                    IsList = true,
                    ItemTypeID = itemType,
                    Items = new ObservableCollection<Item>(),
                    Created = now,
                    LastModified = now
                };
                folder.Items.Add(listItem);

                // store the client or phone client folder
                if (folder.Name == SystemEntities.Client)
                    StorageHelper.WriteClient(folder);
                else if (folder.Name == SystemEntities.PhoneClient)
                    StorageHelper.WritePhoneClient(folder);

                // queue up a server request
                if (folder.ID != Guid.Empty)
                {
                    RequestQueue.EnqueueRequestRecord(RequestQueue.SystemQueue, new RequestQueue.RequestRecord()
                    {
                        ReqType = RequestQueue.RequestRecord.RequestType.Insert,
                        Body = listItem,
                        ID = listItem.ID,
                        IsDefaultObject = true
                    });
                }
            }

            return listItem;
        }
Ejemplo n.º 14
0
        // When page is navigated to set data context to selected item in itemType
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // trace event
            TraceHelper.AddMessage("Item: OnNavigatedTo");

            // check to make sure we haven't initialized yet
            if (isInitialized == true)
                return;

            // create the keyboard helper for tabbed navigation
            this.keyboardHelper = new KeyboardHelper(LayoutRoot);

            // reset the tab index
            tabIndex = 0;

            // render the folder field by default
            bool renderListInfo = false;

            // find the folder that this item would belong to
            string folderIDString = "";
            if (NavigationContext.QueryString.TryGetValue("folderID", out folderIDString))
            {
                Guid folderID = new Guid(folderIDString);
                if (folderID != Guid.Empty)
                {
                    try
                    {
                        //folder = App.ViewModel.Folders.Single(folder => folder.ID == folderID);
                        folder = App.ViewModel.LoadFolder(folderID);
                    }
                    catch (Exception)
                    {
                        folder = null;
                    }
                }
            }

            // if we haven't found a folder, use the default one
            if (folder == null)
            {
                folder = App.ViewModel.DefaultFolder;
                renderListInfo = true;
            }

            string itemIDString = "";
            // must have a item ID passed (either a valid GUID or "new")
            if (NavigationContext.QueryString.TryGetValue("ID", out itemIDString) == false)
            {
                // trace page navigation
                TraceHelper.StartMessage("Item: Navigate back");

                NavigationService.GoBack();
                return;
            }

            // the item page is used to construct a new item
            if (itemIDString == "new")
            {
                // remove the "actions" tab
                //ItemPagePivotControl.Items.RemoveAt(0);
                //((PivotItem)(ItemPagePivotControl.Items[0])).IsEnabled = false;
                itemCopy = new Item() { FolderID = folder.ID };
                thisItem = null;
                RenderViewItem(itemCopy);
                RenderEditItem(itemCopy, renderListInfo);

                // navigate the pivot control to the "edit" view
                ItemPagePivotControl.SelectedIndex = 1;
            }
            else
            {
                // editing an existing item
                Guid id = new Guid(itemIDString);
                //thisItem = App.ViewModel.Items.Single(t => t.ID == id);
                //folder = App.ViewModel.Folders.Single(folder => folder.ID == thisItem.FolderID);

                thisItem = folder.Items.FirstOrDefault(t => t.ID == id);
                if (thisItem == null)
                {
                    // trace page navigation
                    TraceHelper.StartMessage("Item: Navigate back");
                    NavigationService.GoBack();
                    return;
                }

                // make a deep copy of the item for local binding
                itemCopy = new Item(thisItem);
                ItemPagePivotControl.DataContext = itemCopy;
                RenderViewItem(itemCopy);
                RenderEditItem(itemCopy, false /* don't render the list info as primray fields */);
            }

            // set the initialized flag
            isInitialized = true;
        }
Ejemplo n.º 15
0
 private static Item GetListMetadataList(Folder phoneClient)
 {
     return GetOrCreateList(phoneClient, SystemEntities.ListMetadata, SystemItemTypes.Reference);
 }
Ejemplo n.º 16
0
        private void CreateItem(string name, Folder folder, ItemType itemType, Guid parentID)
        {
            // figure out the sort value
            float sortOrder = 1000f;
            var listItems = folder.Items.Where(it => it.ParentID == parentID).ToList();
            if (listItems.Count > 0)
                sortOrder += listItems.Max(it => it.SortOrder);

            // create the new item
            Item item = new Item()
            {
                Name = name,
                FolderID = folder.ID,
                ItemTypeID = itemType.ID,
                ParentID = parentID,
                SortOrder = sortOrder
            };

            // hack: special case processing for item types that have a Complete field
            // if it exists, set it to false
            if (itemType.HasField("Complete"))
                item.Complete = false;

            // enqueue the Web Request Record
            RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue,
                new RequestQueue.RequestRecord()
                {
                    ReqType = RequestQueue.RequestRecord.RequestType.Insert,
                    Body = item
                });

            // add the item to the folder
            folder.Items.Add(item);
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Find a item by ID and then return its index 
 /// </summary>
 /// <param name="observableCollection"></param>
 /// <param name="folder"></param>
 /// <returns></returns>
 private int IndexOf(Folder folder, Item item)
 {
     try
     {
         Item itemRef = folder.Items.Single(t => t.ID == item.ID);
         return folder.Items.IndexOf(itemRef);
     }
     catch (Exception)
     {
         return -1;
     }
 }
Ejemplo n.º 18
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");
        }
Ejemplo n.º 19
0
        public static void StoreListMetadataValue(Folder phoneClient, ClientEntity list, string fieldName, string value)
        {
            if (phoneClient == null)
                return;

            var listsMetadata = GetListMetadataList(phoneClient);
            var listID = list.ID.ToString();
            if (phoneClient.Items.Any(i =>
                i.ParentID == listsMetadata.ID &&
                i.FieldValues.Any(fv => fv.FieldName == FieldNames.EntityRef && fv.Value == listID)))
            {
                var metadataItem = phoneClient.Items.Single(i =>
                    i.ParentID == listsMetadata.ID &&
                    i.FieldValues.Any(fv => fv.FieldName == FieldNames.EntityRef && fv.Value == listID));
                Item copy = new Item(metadataItem);
                var fieldValue = metadataItem.GetFieldValue(fieldName, true);
                fieldValue.Value = value;

                // queue up a server request
                if (phoneClient.ID != Guid.Empty)
                {
                    RequestQueue.EnqueueRequestRecord(RequestQueue.SystemQueue, new RequestQueue.RequestRecord()
                    {
                        ReqType = RequestQueue.RequestRecord.RequestType.Update,
                        Body = new List<Item>() { copy, metadataItem },
                        BodyTypeName = "Item",
                        ID = metadataItem.ID,
                        IsDefaultObject = true
                    });
                }
            }
            else
            {
                Guid id = Guid.NewGuid();
                DateTime now = DateTime.UtcNow;
                var metadataItem = new Item()
                {
                    ID = id,
                    Name = list.Name,
                    ItemTypeID = SystemItemTypes.Reference,
                    FolderID = phoneClient.ID,
                    ParentID = listsMetadata.ID,
                    Created = now,
                    LastModified = now,
                    FieldValues = new ObservableCollection<FieldValue>()
                    {
                        new FieldValue()
                        {
                            ItemID = id,
                            FieldName = FieldNames.EntityRef,
                            Value = list.ID.ToString(),
                        },
                        new FieldValue()
                        {
                            ItemID = id,
                            FieldName = FieldNames.EntityType,
                            Value = list.GetType().Name,
                        },
                        new FieldValue()
                        {
                            ItemID = id,
                            FieldName = fieldName,
                            Value = value
                        }
                    }
                };
                phoneClient.Items.Add(metadataItem);

                // queue up a server request
                if (phoneClient.ID != Guid.Empty)
                {
                    RequestQueue.EnqueueRequestRecord(RequestQueue.SystemQueue, new RequestQueue.RequestRecord()
                    {
                        ReqType = RequestQueue.RequestRecord.RequestType.Insert,
                        Body = metadataItem,
                        ID = metadataItem.ID,
                        IsDefaultObject = true
                    });
                }
            }

            // store the phone client folder
            StorageHelper.WritePhoneClient(phoneClient);
        }
Ejemplo n.º 20
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            // get the name of the folder
            folderCopy.Name = ListName.Text;
            var itemType = ItemTypePicker.SelectedItem as ItemType;
            folderCopy.ItemTypeID = itemType != null ? itemType.ID : SystemItemTypes.Task;

            // check for appropriate values
            if (folderCopy.Name == "")
            {
                MessageBox.Show("folder name cannot be empty");
                return;
            }

            // if this is a new folder, create it
            if (folder == null)
            {
                folder = folderCopy;

                // figure out the sort value
                float sortOrder = 1000f;
                if (App.ViewModel.Folders.Count > 0)
                    sortOrder += App.ViewModel.Folders.Max(f => f.SortOrder);
                folder.SortOrder = sortOrder;

                // enqueue the Web Request Record (with a new copy of the folder)
                // need to create a copy because otherwise other items may be added to it
                // and we want the record to have exactly one operation in it (create the folder)
                RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue,
                    new RequestQueue.RequestRecord()
                    {
                        ReqType = RequestQueue.RequestRecord.RequestType.Insert,
                        Body = new Folder(folder)
                    });

                // add the item to the local itemType
                App.ViewModel.Folders.Add(folder);
            }
            else // this is an update
            {
                // enqueue the Web Request Record
                RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue,
                    new RequestQueue.RequestRecord()
                    {
                        ReqType = RequestQueue.RequestRecord.RequestType.Update,
                        Body = new List<Folder>() { folder, folderCopy },
                        BodyTypeName = "Folder",
                        ID = folder.ID
                    });

                // save the changes to the existing folder (make a deep copy)
                folder.Copy(folderCopy, true);
            }

            // save the changes to local storage
            StorageHelper.WriteFolder(folder);
            StorageHelper.WriteFolders(App.ViewModel.Folders);

            // trigger a sync with the Service
            App.ViewModel.SyncWithService();

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

            // Navigate back to the main page
            NavigationService.GoBack();
        }
Ejemplo n.º 21
0
 public Folder(Folder folder, bool deepCopy)
 {
     Copy(folder, deepCopy);
 }
Ejemplo n.º 22
0
 public Folder(Folder folder)
 {
     Copy(folder, true);
 }
Ejemplo n.º 23
0
        public void Copy(Folder obj, bool deepCopy)
        {
            if (obj == null)
                return;

            // copy all of the properties
            foreach (PropertyInfo pi in this.GetType().GetProperties())
            {
                if (pi.CanWrite)
                {
                    var val = pi.GetValue(obj, null);
                    pi.SetValue(this, val, null);
                }
            }

            if (deepCopy)
            {
                // reinitialize the Items collection
                this.items = new ObservableCollection<Item>();
                foreach (Item t in obj.items)
                {
                    this.items.Add(new Item(t));
                }
            }
            else
            {
                this.items = new ObservableCollection<Item>();
            }

            NotifyPropertyChanged("Items");
        }
Ejemplo n.º 24
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // trace event
            TraceHelper.AddMessage("ListEditor: OnNavigatedTo");

            if (e.NavigationMode == NavigationMode.Back)
                return;

            string folderIDString = "";
            string listIDString = "";

            if (NavigationContext.QueryString.TryGetValue("FolderID", out folderIDString) == false)
            {
                TraceHelper.AddMessage("ListEditor: no folder ID passed in");
                NavigationService.GoBack();
                return;
            }

            Guid folderID = new Guid(folderIDString);
            folder = App.ViewModel.Folders.Single<Folder>(f => f.ID == folderID);

            if (NavigationContext.QueryString.TryGetValue("ID", out listIDString))
            {
                if (listIDString == "new")
                {
                    string parentIDString = "";
                    if (NavigationContext.QueryString.TryGetValue("ParentID", out parentIDString) == false)
                    {
                        TraceHelper.AddMessage("ListEditor: no parent ID passed in");
                        NavigationService.GoBack();
                        return;
                    }

                    // new list
                    DateTime now = DateTime.UtcNow;
                    Guid? parentID = String.IsNullOrEmpty(parentIDString) ? (Guid?)null : new Guid(parentIDString);
                    Item parent = parentID != null ? App.ViewModel.Items.FirstOrDefault(i => i.ParentID == parentID) : null;

                    listCopy = new Item()
                    {
                        FolderID = folderID,
                        ParentID = String.IsNullOrEmpty(parentIDString) ? (Guid?)null : new Guid(parentIDString),
                        IsList = true,
                        ItemTypeID = parent != null ? parent.ItemTypeID : folder.ItemTypeID,
                        Created = now,
                        LastModified = now
                    };
                    TitlePanel.DataContext = listCopy;
                }
                else
                {
                    Guid listID = new Guid(listIDString);
                    list = folder.Items.Single<Item>(l => l.ID == listID);

                    // make a deep copy of the item for local binding
                    listCopy = new Item(list);
                    TitlePanel.DataContext = listCopy;

                    // add the delete button to the ApplicationBar
                    var button = new ApplicationBarIconButton() { Text = "Delete", IconUri = new Uri("/Images/appbar.delete.rest.png", UriKind.Relative) };
                    button.Click += new EventHandler(DeleteButton_Click);

                    // insert after the save button but before the cancel button
                    ApplicationBar.Buttons.Add(button);
                }

                // set up the item type listpicker
                var itemTypes = App.ViewModel.ItemTypes.Where(i => i.UserID != SystemUsers.System).OrderBy(i => i.Name).ToList();
                ItemTypePicker.ItemsSource = itemTypes;
                ItemTypePicker.DisplayMemberPath = "Name";
                ItemType thisItemType = itemTypes.FirstOrDefault(i => i.ID == listCopy.ItemTypeID);
                ItemTypePicker.SelectedIndex = Math.Max(itemTypes.IndexOf(thisItemType), 0);
            }
        }
Ejemplo n.º 25
0
        private void AddItem(Folder folder, Item list)
        {
            string name = NameTextBox.Text;

            // don't add empty items - instead, navigate to the list
            if (name == null || name == "")
            {
                TraceHelper.StartMessage("AddPage: Navigate to List");
                NavigationService.Navigate(new Uri(
                    String.Format(
                        "/ListPage.xaml?type=Folder&ID={0}&ParentID={1}",
                        folder.ID,
                        list != null ? list.ID : Guid.Empty),
                    UriKind.Relative));
                return;
            }

            Guid itemTypeID;
            Guid parentID;
            if (list == null)
            {
                itemTypeID = folder.ItemTypeID;
                parentID = Guid.Empty;
            }
            else
            {
                itemTypeID = list.ItemTypeID;
                parentID = list.ID;
            }

            // get a reference to the item type
            ItemType itemType = App.ViewModel.ItemTypes.Single(it => it.ID == itemTypeID);

            // special case grocery items - split the name by comma and add a new grocery item for each string
            if (itemTypeID == SystemItemTypes.Grocery)
                foreach (var si in name.Split(','))
                    CreateItem(si.Trim(), folder, itemType, parentID);
            else
                CreateItem(name, folder, itemType, parentID);

            // save the changes to local storage
            StorageHelper.WriteFolder(folder);

            // trigger a sync with the Service
            App.ViewModel.SyncWithService();

            // reset the name field to make it easy to add the next one
            NameTextBox.Text = "";
        }
Ejemplo n.º 26
0
 public static void StoreListSortOrder(Folder phoneClient, ClientEntity list, string listSortOrder)
 {
     StoreListMetadataValue(phoneClient, list, ExtendedFieldNames.SortBy, listSortOrder);
 }
Ejemplo n.º 27
0
        public void SaveButton_Click(object sender, EventArgs e)
        {
            // update the LastModified timestamp
            ThisItem.LastModified = DateTime.UtcNow;

            // parse common regexps out of the description and into the appropriate
            // fields (phone, email, URL, etc)
            ParseFields(ThisItem);

            // remove any NEW FieldValues (i.e. ones which didn't exist on the original item)
            // which contain null Values (we don't want to burden the item with
            // extraneous null fields)
            List<FieldValue> fieldValues = new List<FieldValue>(ThisItem.FieldValues);
            foreach (var fv in fieldValues)
                if (fv.Value == null && (ItemCopy == null || ItemCopy.GetFieldValue(fv.FieldName, false) == null))
                    ThisItem.RemoveFieldValue(fv);

            // enqueue the Web Request Record
            RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue,
                new RequestQueue.RequestRecord()
                {
                    ReqType = RequestQueue.RequestRecord.RequestType.Update,
                    Body = new List<Item>() { ItemCopy, ThisItem },
                    BodyTypeName = "Item",
                    ID = ThisItem.ID
                });

            // create a copy of the new baseline
            ItemCopy = new Item(ThisItem, true);

            // reload the folder in case it changed
            folder = App.ViewModel.Folders.Single(f => f.ID == folder.ID);

            // save the changes to local storage
            if (folder.Items.Any(i => i.ID == ThisItem.ID))
            {
                var existingItem = folder.Items.Single(i => i.ID == ThisItem.ID);
                if (existingItem != ThisItem)
                    existingItem.Copy(ThisItem, true);
            }
            else
            {
                TraceHelper.AddMessage("ItemPage: cannot find existing item to update");
                folder.Items.Add(ThisItem);
            }
            StorageHelper.WriteFolder(folder);

            // trigger a sync with the Service
            App.ViewModel.SyncWithService();
        }
Ejemplo n.º 28
0
 private static Item GetDefaultListsList(Folder client)
 {
     return GetOrCreateList(client, SystemEntities.DefaultLists, SystemItemTypes.NameValue);
 }
Ejemplo n.º 29
0
        public void PushViewController()
        {
            // trace event
            TraceHelper.AddMessage("Item: PushViewController");

            try
            {
                folder = App.ViewModel.LoadFolder(ThisItem.FolderID);
            }
            catch (Exception)
            {
                folder = null;
                return;
            }

            // make a deep copy of the item which stores the previous values
            // the iphone implementation will make changes to the "live" copy
            ItemCopy = new Item(ThisItem);
            root = RenderViewItem(ThisItem);
            actionsViewController = new DialogViewController (root, true);

            // create an Edit button which pushes the edit view onto the nav stack
            actionsViewController.NavigationItem.RightBarButtonItem = new UIBarButtonItem (UIBarButtonSystemItem.Edit, delegate {
                var editRoot = RenderEditItem(ThisItem, false);
                editViewController = new DialogViewController(editRoot, true);
                editViewController.NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Done, delegate {
                    // save the item and trigger a sync with the service
                    SaveButton_Click(null, null);
                    // navigate back to the list page
                    TraceHelper.StartMessage("Item: Navigate back");
                    NavigateBack();
                });

                UIImage actionsBackButtonImage = UIImageCache.GetUIImage("Images/actions-back-button.png");
                UIImage actionsBackButtonImageSelected = UIImageCache.GetUIImage("Images/actions-back-button-selected.png");
                UIButton actionsBackButton = UIButton.FromType(UIButtonType.Custom);
                actionsBackButton.SetImage(actionsBackButtonImage, UIControlState.Normal);
                actionsBackButton.SetImage(actionsBackButtonImageSelected, UIControlState.Selected);
                actionsBackButton.SetImage(actionsBackButtonImageSelected, UIControlState.Highlighted);
                actionsBackButton.Frame = new System.Drawing.RectangleF(0, 0, actionsBackButtonImage.Size.Width, actionsBackButtonImage.Size.Height);
                actionsBackButton.TouchUpInside += delegate {
                    // save the item and trigger a sync with the service
                    SaveButton_Click(null, null);
                    // reload the Actions page
                    var oldroot = root;
                    root = RenderViewItem(ThisItem);
                    actionsViewController.Root = root;
                    actionsViewController.ReloadData();
                    oldroot.Dispose();
                    // pop back to actions page
                    controller.PopViewControllerAnimated(true);
                };
                UIBarButtonItem actionsBackBarItem = new UIBarButtonItem(actionsBackButton);
                editViewController.NavigationItem.LeftBarButtonItem = actionsBackBarItem;
                editViewController.TableView.BackgroundColor = UIColorHelper.FromString(App.ViewModel.Theme.PageBackground);
                controller.PushViewController(editViewController, true);
            });

            // if moving from the item page to its parent (e.g. the schedule tab), call ViewDidAppear on that controller
            actionsViewController.ViewDisappearing += (sender, e) =>
            {
                /*
                if (UIDevice.CurrentDevice.CheckSystemVersion(5, 0))
                {
                    // this property should be called "IsMovingToParentViewController" - it is a bug in the property naming,
                    // not a bug in the code
                    if (actionsViewController.IsMovingFromParentViewController)
                        controller.ViewDidAppear(false);
                }
                */
                // the IsMovingToParentViewController method is only available on iOS 5.0 so the code above doesn't work generally.
                // it does not appear to hurt anything to always call ViewDidAppear (even when pushing deeper into the nav stack)
                controller.ViewDidAppear(false);
            };

            // push the "view item" view onto the nav stack
            actionsViewController.TableView.BackgroundColor = UIColorHelper.FromString(App.ViewModel.Theme.PageBackground);
            controller.PushViewController(actionsViewController, true);
        }
Ejemplo n.º 30
0
 public static void StoreTheme(Folder phoneClient, string value)
 {
     StorePhoneSetting(phoneClient, PhoneSettings.Theme, value);
 }