This commit is contained in:
467
source/WBI/WikiEdit.aspx.cs
Normal file
467
source/WBI/WikiEdit.aspx.cs
Normal file
@@ -0,0 +1,467 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Configuration;
|
||||
using System.Collections;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web.UI.WebControls.WebParts;
|
||||
using System.Web.UI.HtmlControls;
|
||||
using GZTW.AyaNova.BLL;
|
||||
using Telerik.Web.UI;
|
||||
using Telerik.Web.UI.Widgets;
|
||||
using System.IO;
|
||||
|
||||
public partial class WikiEdit : BaseEditPage
|
||||
{
|
||||
#region BizObject
|
||||
public WikiPage mWikiPage;
|
||||
protected WikiPage CurrentWikiPage
|
||||
{
|
||||
get
|
||||
{
|
||||
if (mWikiPage != null) return mWikiPage;
|
||||
|
||||
string idstring = Request.QueryString["id"];
|
||||
Guid oID = Guid.Empty;
|
||||
if (!string.IsNullOrEmpty(idstring))
|
||||
oID = new Guid(idstring);
|
||||
|
||||
mWikiPage = (WikiPage)Session["wikipage"];
|
||||
//ensure if object in session is the same as the one requested
|
||||
if (mWikiPage == null || (oID != Guid.Empty && mWikiPage.ID != oID))//Case 912
|
||||
{
|
||||
try
|
||||
{
|
||||
if (oID != Guid.Empty)
|
||||
mWikiPage = WikiPage.GetItem(oID);
|
||||
else
|
||||
{
|
||||
throw new System.NotSupportedException("WikiEdit->No WikiPage found for object");
|
||||
|
||||
}
|
||||
|
||||
Session["wikipage"] = mWikiPage;
|
||||
}
|
||||
catch (System.Security.SecurityException)
|
||||
{
|
||||
CloseMe();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//if (!WikiPage.CanEditWikiPage(mWikiPage.ExactRootObjectType, mWikiPage.RootObjectID))//case 1584
|
||||
//{
|
||||
// Util.Denied(Context);
|
||||
// return null;
|
||||
//}
|
||||
|
||||
return mWikiPage;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Page events
|
||||
|
||||
|
||||
|
||||
protected void Page_Init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#region customize editor
|
||||
|
||||
public void RemoveButtons()
|
||||
{
|
||||
ed.EnsureToolsFileLoaded();
|
||||
//Customize the editor toolbar buttons
|
||||
ed.EnsureToolsFileLoaded();
|
||||
//Removing spell check turns off error about dictionaries
|
||||
RemoveButton("AjaxSpellCheck");
|
||||
RemoveButton("ModuleManager");
|
||||
|
||||
//TAble related
|
||||
RemoveButton("InsertTable");
|
||||
RemoveButton("ToggleTableBorder");
|
||||
|
||||
RemoveButton("Zoom");
|
||||
RemoveButton("ToggleDocking");
|
||||
RemoveButton("AboutDialog");
|
||||
RemoveButton("ImageMapDialog");
|
||||
RemoveButton("AbsolutePosition");
|
||||
RemoveButton("InsertSnippet");
|
||||
RemoveButton("InsertFormElement");
|
||||
RemoveButton("FlashManager");
|
||||
RemoveButton("MediaManager");
|
||||
|
||||
RemoveButton("DocumentManager");
|
||||
RemoveButton("LinkManager");
|
||||
RemoveButton("Unlink");
|
||||
RemoveButton("InsertCustomLink");
|
||||
RemoveButton("TemplateManager");
|
||||
RemoveButton("InsertHorizontalRule");
|
||||
RemoveButton("FormatCodeBlock");
|
||||
RemoveButton("ApplyClass");
|
||||
RemoveButton("InsertGroupBox");
|
||||
|
||||
|
||||
|
||||
}
|
||||
public void RemoveButton(string name)
|
||||
{
|
||||
foreach (Telerik.Web.UI.EditorToolGroup group in ed.Tools)
|
||||
{
|
||||
EditorTool tool = group.FindTool(name);
|
||||
if (tool != null)
|
||||
{
|
||||
group.Tools.Remove(tool);
|
||||
//hack to remove group with nothing but separators in it
|
||||
//because none of the built in toolbars we want
|
||||
//has less than three icons in them
|
||||
if (group.Tools.Count <3 )
|
||||
ed.Tools.Remove(group);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion customize editor
|
||||
|
||||
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
//string s=System.Threading.Thread.CurrentThread.CurrentCulture.ToString();
|
||||
//don't process the following on an ajax callback
|
||||
if (IsCallback) return;
|
||||
|
||||
//Initialize controls on first page load
|
||||
if (!this.IsPostBack)
|
||||
{
|
||||
//Item zero is always the print menu
|
||||
//Master.Menu.Items[0].Hidden=true;
|
||||
}
|
||||
|
||||
RemoveButtons();
|
||||
|
||||
ed.ImageManager.ContentProviderTypeName = typeof(WBIContentProvider).AssemblyQualifiedName;
|
||||
|
||||
ed.ImageManager.ViewPaths = new string[] { this.CurrentWikiPage.ID.ToString(), "IMAGE" };
|
||||
ed.ImageManager.UploadPaths = new string[] { "ImageUploadPath" };
|
||||
ed.ImageManager.EnableImageEditor = false;
|
||||
|
||||
ed.DisableFilter(Telerik.Web.UI.EditorFilters.ConvertFontToSpan);
|
||||
|
||||
//ed.DocumentManager.ContentProviderTypeName = typeof(WBIContentProvider).AssemblyQualifiedName;
|
||||
//ed.DocumentManager.ViewPaths = new string[] { this.CurrentWikiPage.ID.ToString(), "FILE" };
|
||||
//ed.DocumentManager.UploadPaths = new string[] { "DOCUploadPath" };
|
||||
//ed.DocumentManager.SearchPatterns = new string[] { "*.*" };
|
||||
}
|
||||
|
||||
protected void Page_LoadComplete(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
|
||||
////don't process the following on an ajax callback
|
||||
//if (IsCallback) return;
|
||||
|
||||
////Get data logic
|
||||
//if (this.IsPostBack)//Only on a postback
|
||||
//{
|
||||
// //Only if user isn't closing form outright without saving
|
||||
// if (Master.AyMessage == null || Master.AyMessage.Message != "LT:UI.Command.Close")
|
||||
// {
|
||||
// GetData();
|
||||
// }
|
||||
|
||||
// if (Master.AyMessage != null)
|
||||
// HandleAyMessage();
|
||||
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
//Case 308 replicated following block from client form
|
||||
|
||||
//Get data logic
|
||||
if (this.IsPostBack && !IsAjaxCallback)//Only on a postback and not a callback
|
||||
{
|
||||
GetData();
|
||||
}
|
||||
|
||||
//Load and set data in initial form load
|
||||
//and in all postbacks that are not a result of a rad
|
||||
//manager callback
|
||||
if (!IsAjaxCallback)
|
||||
{
|
||||
//Localize the page
|
||||
Util.Localize(this.Page);
|
||||
SetData();
|
||||
|
||||
}
|
||||
|
||||
if (Master.AyMessage != null)
|
||||
HandleAyMessage();
|
||||
|
||||
}
|
||||
#endregion page events
|
||||
|
||||
#region Set / get data
|
||||
private void SetData()
|
||||
{
|
||||
|
||||
WikiPage o = CurrentWikiPage;
|
||||
|
||||
this.Title = Util.LocaleText("O.WikiPage") + " - " + NameFetcher.GetItem(new TypeAndID(mWikiPage.RootObjectType, mWikiPage.RootObjectID)).RecordName;
|
||||
|
||||
|
||||
ed.Content = o.GetContentAsWBIReadyHTML(true);
|
||||
|
||||
}
|
||||
|
||||
private void GetData()
|
||||
{
|
||||
|
||||
WikiPage o = CurrentWikiPage;
|
||||
//string s = ed.Content;
|
||||
o.SetContentFromWBI(ed.Content);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Toolbar and other master page messages
|
||||
|
||||
/// <summary>
|
||||
/// Messages from master page
|
||||
/// </summary>
|
||||
void HandleAyMessage()
|
||||
{
|
||||
switch (Master.AyMessage.MessageType)
|
||||
{
|
||||
case AYMessageType.ToolBarClick:
|
||||
{
|
||||
switch (Master.AyMessage.Message)
|
||||
{
|
||||
case "LT:UI.Command.Close":
|
||||
CloseForm();
|
||||
break;
|
||||
case "LT:UI.Command.Save":
|
||||
SaveRecord();
|
||||
break;
|
||||
case "LT:UI.Command.SaveClose":
|
||||
if (SaveRecord())
|
||||
CloseForm();
|
||||
break;
|
||||
case "LT:UI.Command.Delete":
|
||||
WikiPage.DeleteItem(CurrentWikiPage.ID);
|
||||
CloseForm();
|
||||
break;
|
||||
case "LT:UI.Command.SaveNew":
|
||||
if (SaveRecord())
|
||||
{
|
||||
Session.Remove("wikipage");
|
||||
mWikiPage = null;
|
||||
Response.Redirect("WikiPageEdit.aspx");
|
||||
}
|
||||
break;
|
||||
case "LT:UI.Command.RecordHistory":
|
||||
|
||||
Util.PopupAlert(this.Page,Util.RecordHistoryText(
|
||||
CurrentWikiPage.Creator,
|
||||
CurrentWikiPage.Modifier,
|
||||
CurrentWikiPage.Created,
|
||||
CurrentWikiPage.Modified
|
||||
));
|
||||
break;
|
||||
//case "LT:AssignedDoc.Label.List":
|
||||
// Response.Redirect("stub.aspx");
|
||||
// break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private bool SaveRecord()
|
||||
{
|
||||
if (!CurrentWikiPage.IsDirty) return true;
|
||||
if (CurrentWikiPage.IsSavable)
|
||||
{
|
||||
Session["wikipage"] = mWikiPage = (WikiPage)mWikiPage.Save();
|
||||
|
||||
this.Master.SetErrors("");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//display broken rules, or whatever, see book
|
||||
this.Master.SetErrors(mWikiPage.BrokenRulesText);
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void CloseForm()
|
||||
{
|
||||
Session.Remove("wikipage");
|
||||
CloseMe();
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
#region Custom content provider
|
||||
/// <summary>
|
||||
/// Summary description for WBIContentProvider
|
||||
/// </summary>
|
||||
public class WBIContentProvider : FileBrowserContentProvider
|
||||
{
|
||||
//http://demos.telerik.com/ASPNET/prometheus/Editor/Examples/DBFileBrowserContentProvider/DefaultCS.aspx
|
||||
|
||||
private PathPermissions fullPermissions = PathPermissions.Read | PathPermissions.Delete | PathPermissions.Upload;
|
||||
|
||||
public WBIContentProvider(HttpContext context, string[] searchPatterns,
|
||||
string[] viewPaths, string[] uploadPaths, string[] deletePaths, string selectedUrl,
|
||||
string selectedItemTag)
|
||||
:
|
||||
base(context, searchPatterns, viewPaths, uploadPaths, deletePaths, selectedUrl, selectedItemTag)
|
||||
{
|
||||
mWikiPageID = new Guid(viewPaths[0]);
|
||||
mlist = AyaFileList.GetList(mWikiPageID);
|
||||
mFileType = viewPaths[1];
|
||||
|
||||
}
|
||||
string mFileType = "";
|
||||
AyaFileList mlist = null;
|
||||
Guid mWikiPageID = Guid.Empty;
|
||||
public override string CreateDirectory(string path, string name)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override string DeleteDirectory(string path)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override string DeleteFile(string path)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override System.IO.Stream GetFile(string url)
|
||||
{
|
||||
string sFileName = Path.GetFileName(url);
|
||||
if (this.mlist.Contains(sFileName))
|
||||
{
|
||||
//return it as a stream
|
||||
AyaFileList.AyaFileListInfo? i=mlist[sFileName];
|
||||
if(i.HasValue)
|
||||
{
|
||||
AyaFile af = AyaFile.GetItem(i.Value.LT_O_AyaFile.Value);
|
||||
return af.GetContent();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public override string GetFileName(string url)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override string GetPath(string url)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override DirectoryItem ResolveDirectory(string path)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override DirectoryItem[] ResolveRootDirectoryAsList(string path)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private int nRootsAdded = 0;
|
||||
public override DirectoryItem ResolveRootDirectoryAsTree(string path)
|
||||
{
|
||||
if (nRootsAdded > 0) return null;
|
||||
DirectoryItem di = new DirectoryItem("AyaFiles","","","",fullPermissions,GetChildFiles(path),new DirectoryItem[] { });
|
||||
nRootsAdded++;
|
||||
return di;
|
||||
//throw new NotImplementedException();//ifst
|
||||
}
|
||||
|
||||
public override string StoreBitmap(System.Drawing.Bitmap bitmap, string url, System.Drawing.Imaging.ImageFormat format)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override string StoreFile(Telerik.Web.UI.UploadedFile file, string path, string name, params string[] arguments)
|
||||
{
|
||||
|
||||
//replacing a file?
|
||||
if (mlist.Contains(name))
|
||||
{ //delete the old one first so no dupes hanging around
|
||||
AyaFile.DeleteItem(mlist[name].Value.LT_O_AyaFile.Value);
|
||||
}
|
||||
|
||||
//Store the file
|
||||
AyaFile af = AyaFile.NewItem();
|
||||
af.FileType = AyaFileType.EmbeddedWikiImage;
|
||||
af.Name = name;
|
||||
af.RootObjectID = mWikiPageID;
|
||||
af.RootObjectType = RootObjectTypes.WikiPage;
|
||||
af.SetContent(file.InputStream);
|
||||
af.Save();
|
||||
//mlist = AyaFileList.GetList(mWikiPageID);
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
|
||||
private FileItem[] GetChildFiles(string _path)
|
||||
{
|
||||
|
||||
ArrayList files = new ArrayList();
|
||||
|
||||
foreach (AyaFileList.AyaFileListInfo i in mlist)
|
||||
{
|
||||
string name = i.LT_O_AyaFile.Display;
|
||||
string itemurl = "";
|
||||
|
||||
if (mFileType == "IMAGE" && i.FileType== AyaFileType.EmbeddedWikiImage)
|
||||
{
|
||||
itemurl = "AyaImage.ashx?id=" + i.LT_O_AyaFile.Value.ToString();
|
||||
files.Add(
|
||||
new FileItem(name, Path.GetExtension(name), (long)i.FileSizeBytes, string.Empty, itemurl,
|
||||
i.LT_O_AyaFile.Value.ToString(), fullPermissions));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mFileType == "FILE" && i.FileType!= AyaFileType.EmbeddedWikiImage)
|
||||
{
|
||||
itemurl = "AyaFileHandler.ashx?id=" + i.LT_O_AyaFile.Value.ToString();
|
||||
files.Add(
|
||||
new FileItem(name, Path.GetExtension(name), (long)i.FileSizeBytes, string.Empty, itemurl,
|
||||
i.LT_O_AyaFile.Value.ToString(), fullPermissions));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return (FileItem[])files.ToArray(typeof(FileItem));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
Reference in New Issue
Block a user