Exemple #1
0
 internal static async void Upload(Folder folder, HtmlCollection <File> files)
 {
     if (files.Length == 1)
     {
         File     file     = files[0];
         ListItem listItem = null;
         if (await LazyWindow.ShowWaiting(string.Format("{0}: uploading...", file.Name),
                                          async delegate(CancellationToken cancellationToken)
         {
             listItem = await folder.Upload(file, cancellationToken);
         }))
         {
             ListItemEditor.Show(new EditAction()
             {
                 EditMode   = EditMode.Edit,
                 ListItem   = listItem,
                 TargetList = listItem.ParentList
             });
         }
     }
     else
     {
         for (int i = 0; i < files.Length; i++)
         {
             if (!await LazyWindow.ShowWaiting(string.Format("{0}: uploading...", files[i].Name),
                                               delegate(CancellationToken cancellation)
             {
                 return(folder.Upload(files[i], cancellation));
             }))
             {
                 break;
             }
         }
     }
 }
 internal async void DeleteItem(ListItem listItem)
 {
     if (await MessageBox.Show(string.Format("Are you sure to delete item (ID={0})", listItem.ID),
                               "Deleting...",
                               MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
     {
         await LazyWindow.ShowWaiting(listItem.Delete);
     }
 }
Exemple #3
0
 internal static async void DeleteFolder(FolderNode folder)
 {
     if (await MessageBox.Show(string.Format("Are you sure to delete folder '{0}'", folder.Name),
                               "Deleting...",
                               MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
     {
         await LazyWindow.ShowWaiting(folder.Item.Delete);
     }
 }
 internal static void Show(ListContentType contentType)
 {
     LazyWindow.ShowWaiting();
     contentType.Detail.Get(delegate(ContentTypeDetail detail)
     {
         LazyWindow.HideWaiting();
         new ContentTypeEditor(contentType).Show();
     },
                            LazyWindow.ShowError);
 }
Exemple #5
0
        internal async void SaveConfiguration()
        {
            string json = JsonSerializer.Serialize(RootNodes.Configuration);

            if (await LazyWindow.ShowWaiting("Saving configuration...",
                                             async delegate()
            {
                await webPart.UpdateSettings(json);
            }))
            {
                await MessageBox.Show(string.Format("Configuration has been successfully saved."));
            }
        }
Exemple #6
0
 internal static async void Upload(ListItem listItem, HtmlCollection <File> files)
 {
     for (int i = 0; i < files.Length; i++)
     {
         if (!await LazyWindow.ShowWaiting(string.Format("{0}: uploading...", files[i].Name),
                                           delegate(CancellationToken cancellationToken)
         {
             return(listItem.AddAttachment(UriUtility.GetFileName(files[i].Name), files[i], cancellationToken));
         }))
         {
             break;
         }
     }
 }
        internal static void Drop(IList <ListItem> source, Folder target)
        {
            if (target != null && source != null && source.Count != 0)
            {
                for (int i = 0; i < source.Count; i++)
                {
                    source[i].MoveTo(target);
                }

                LazyWindow.ShowWaiting(
                    delegate(CancellationToken cancellationToken)
                {
                    return(ListItem.Update(source, cancellationToken));
                });
            }
        }
Exemple #8
0
        async Task ISavable.Save(CancellationToken cancellationToken)
        {
            Url.NotEmpty("Please enter url first!");
            LazyWindow.ShowWaiting();
            RootNode rootNode = new RootNode()
            {
                Url = Url, IsSite = IsSite
            };

            app.ApplyRootUrl(rootNode);
            if (IsSite)
            {
                await rootNode.WebNode.Webs.Get(cancellationToken);
            }
            else
            {
                await rootNode.WebNode.Detail.Get(cancellationToken);
            }

            Add(rootNode);
        }
Exemple #9
0
        async void DeleteSelectedItems()
        {
            if (Overview.RowsSelection.Count != 0)
            {
                JArray <ListItem> listItems = new JArray <ListItem>();
                Overview.RowsSelection.Enumerate(0,
                                                 delegate(ListItem li)
                {
                    if ((li.EffectiveBasePermissions & BasePermissions.DeleteListItems) == BasePermissions.DeleteListItems)
                    {
                        listItems.Push(li);
                    }

                    return(true);
                });

                if (listItems.Length != 0)
                {
                    if (await MessageBox.Show(string.Format("Are you sure to delete {0} selected item(s)", listItems.Length),
                                              "Deleting...",
                                              MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
                    {
                        await LazyWindow.ShowWaiting(
                            delegate(CancellationToken cancellationToken) {
                            return(ListItem.Delete(listItems, cancellationToken));
                        });
                    }
                }
                else
                {
                    await MessageBox.Show("No list items can be deleted.");
                }
            }
            else
            {
                await MessageBox.Show("No list items has been selected to delete.");
            }
        }
        internal static async void Show(EditAction editAction)
        {
            ListItem listItem = null;
            ObservableList <ListContentType> affectedContentTypes = null;
            ListContentType contentType = null;

            if (await LazyWindow.ShowWaiting(
                    async delegate(CancellationToken cancellationToken)
            {
                switch (editAction.EditMode)
                {
                case EditMode.Edit:
                    listItem = await editAction.ListItem.ParentList.GetItemById(editAction.ListItem.ID, cancellationToken);
                    break;

                case EditMode.Copy:
                    listItem = await editAction.ListItem.ParentList.GetItemById(editAction.ListItem.ID, cancellationToken);
                    break;

                case EditMode.AddItem:
                    listItem = editAction.TargetList.Add(FileSystemObjectType.File);
                    listItem.MoveTo(editAction.TargetFolder);
                    break;

                case EditMode.AddFolder:
                    listItem = editAction.TargetList.Add(FileSystemObjectType.Folder);
                    listItem.MoveTo(editAction.TargetFolder);
                    break;

                default:
                    throw new ApplicationException("Unexpected");
                }

                ObservableList <ListContentType> contentTypes = await editAction.TargetList.ContentTypes.GetAsync(cancellationToken);
                affectedContentTypes = new ObservableList <ListContentType>();
                foreach (ListContentType hit in contentTypes)
                {
                    if (hit.ID.StartsWith(BuiltInContentTypeIds.Folder) == (listItem.FileSystemObjectType == FileSystemObjectType.Folder))
                    {
                        affectedContentTypes.Add(hit);
                        if (hit.ID == listItem.ContentTypeId)
                        {
                            contentType = hit;
                        }
                    }
                }
                if (contentType == null && affectedContentTypes.Count != 0)
                {
                    contentType = affectedContentTypes[0];
                    listItem.ContentTypeId = contentType.ID;
                }

                contentType.NotNull("Unknown content type");

                if (editAction.EditMode == EditMode.Copy)
                {
                    ContentTypeDetail contentTypeDetail = await contentType.Detail.GetAsync(cancellationToken);
                    ListItem newListItem = listItem.ParentList.Add(listItem.FileSystemObjectType);
                    newListItem.ContentTypeId = listItem.ContentTypeId;
                    for (int i = 0; i < contentTypeDetail.Fields.Count; i++)
                    {
                        Field field = contentTypeDetail.Fields[i];
                        if (field.ShowInEditForm && !field.ReadOnly)
                        {
                            newListItem[field] = listItem[field];
                        }
                    }
                    newListItem.MoveTo(editAction.TargetFolder);
                    listItem.Dispose();
                    listItem = newListItem;
                }
            }))
            {
                new ListItemEditor(editAction, listItem, affectedContentTypes, contentType);
            }
            else
            {
                listItem?.Dispose();
            }
        }