diff --git a/src/umbraco.editorControls/imagecropper/DataEditor.cs b/src/umbraco.editorControls/imagecropper/DataEditor.cs
index 0e7e2f56cb..62c83a2383 100644
--- a/src/umbraco.editorControls/imagecropper/DataEditor.cs
+++ b/src/umbraco.editorControls/imagecropper/DataEditor.cs
@@ -1,14 +1,13 @@
using System;
+using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
+using System.Xml;
+using umbraco.cms.businesslogic;
+using umbraco.cms.businesslogic.media;
+using umbraco.cms.businesslogic.member;
using umbraco.cms.businesslogic.property;
using umbraco.cms.businesslogic.web;
-using System.Xml;
-using System.Text;
-using umbraco.editorControls.imagecropper;
-using umbraco.cms.businesslogic.media;
-using umbraco.cms.businesslogic;
-using umbraco.cms.businesslogic.member;
namespace umbraco.editorControls.imagecropper
{
@@ -36,7 +35,6 @@ namespace umbraco.editorControls.imagecropper
public Control Editor { get { return this; } }
protected override void OnInit(EventArgs e)
- //protected override void OnLoad(EventArgs e)
{
this.ID = "ImageCropper";
//base.OnInit(e);
@@ -50,133 +48,133 @@ namespace umbraco.editorControls.imagecropper
CMSNode node = new CMSNode(currentDocumentId);
if (node.nodeObjectType == Document._objectType)
{
- uploadProperty =
- new Document(currentDocumentId).getProperty(config.UploadPropertyAlias);
+ uploadProperty = new Document(currentDocumentId).getProperty(config.UploadPropertyAlias);
}
else if (node.nodeObjectType == umbraco.cms.businesslogic.media.Media._objectType)
{
- uploadProperty =
- new Media(currentDocumentId).getProperty(config.UploadPropertyAlias);
+ uploadProperty = new Media(currentDocumentId).getProperty(config.UploadPropertyAlias);
}
else if (node.nodeObjectType == Member._objectType)
{
- uploadProperty =
- new Member(currentDocumentId).getProperty(config.UploadPropertyAlias);
+ uploadProperty = new Member(currentDocumentId).getProperty(config.UploadPropertyAlias);
}
else
{
throw new Exception("Unsupported Umbraco Node type for Image Cropper (only Document, Media and Members are supported.");
}
- string relativeImagePath = uploadProperty.Value.ToString();
-
- ImageInfo imageInfo = new ImageInfo(relativeImagePath);
-
- imgImage.ImageUrl = relativeImagePath;
- imgImage.ID = String.Format("cropBox_{0}", propertyId);
-
- StringBuilder sbJson = new StringBuilder();
- StringBuilder sbRaw = new StringBuilder();
-
- try
+ // upload property could be null here if the property wasn't found
+ if (uploadProperty != null)
{
- _xml = new XmlDocument();
- _xml.LoadXml(data.Value.ToString());
- }
- catch
- {
- _xml = createBaseXmlDocument();
- }
+ string relativeImagePath = uploadProperty.Value.ToString();
- sbJson.Append("{ \"current\": 0, \"crops\": [");
+ ImageInfo imageInfo = new ImageInfo(relativeImagePath);
- for (int i = 0; i < config.presets.Count; i++)
- {
- Preset preset = (Preset)config.presets[i];
- Crop crop;
+ imgImage.ImageUrl = relativeImagePath;
+ imgImage.ID = String.Format("cropBox_{0}", propertyId);
- sbJson.Append("{\"name\":'" + preset.Name + "'");
+ StringBuilder sbJson = new StringBuilder();
+ StringBuilder sbRaw = new StringBuilder();
- sbJson.Append(",\"config\":{" +
- String.Format("\"targetWidth\":{0},\"targetHeight\":{1},\"keepAspect\":{2}",
- preset.TargetWidth, preset.TargetHeight,
- (preset.KeepAspect ? "true" : "false") + "}"));
-
- if (imageInfo.Exists)
+ try
{
- crop = preset.Fit(imageInfo);
+ _xml = new XmlDocument();
+ _xml.LoadXml(data.Value.ToString());
}
- else
+ catch
{
- crop.X = 0;
- crop.Y = 0;
- crop.X2 = preset.TargetWidth;
- crop.Y2 = preset.TargetHeight;
+ _xml = createBaseXmlDocument();
}
- // stored
- if (_xml.DocumentElement != null && _xml.DocumentElement.ChildNodes.Count == config.presets.Count)
+ sbJson.Append("{ \"current\": 0, \"crops\": [");
+
+ for (int i = 0; i < config.presets.Count; i++)
{
- XmlNode xmlNode = _xml.DocumentElement.ChildNodes[i];
+ Preset preset = (Preset)config.presets[i];
+ Crop crop;
- int xml_x = Convert.ToInt32(xmlNode.Attributes["x"].Value);
- int xml_y = Convert.ToInt32(xmlNode.Attributes["y"].Value);
- int xml_x2 = Convert.ToInt32(xmlNode.Attributes["x2"].Value);
- int xml_y2 = Convert.ToInt32(xmlNode.Attributes["y2"].Value);
+ sbJson.Append("{\"name\":'" + preset.Name + "'");
- // only use xml values if image is the same and different from defaults (document is stored inbetween image upload and cropping)
- //if (xml_x2 - xml_x != preset.TargetWidth || xml_y2 - xml_y != preset.TargetHeight)
- //fileDate == imageInfo.DateStamp && (
+ sbJson.Append(",\"config\":{" +
+ String.Format("\"targetWidth\":{0},\"targetHeight\":{1},\"keepAspect\":{2}",
+ preset.TargetWidth, preset.TargetHeight,
+ (preset.KeepAspect ? "true" : "false") + "}"));
- if (crop.X != xml_x || crop.X2 != xml_x2 || crop.Y != xml_y || crop.Y2 != xml_y2)
+ if (imageInfo.Exists)
{
- crop.X = xml_x;
- crop.Y = xml_y;
- crop.X2 = xml_x2;
- crop.Y2 = xml_y2;
+ crop = preset.Fit(imageInfo);
+ }
+ else
+ {
+ crop.X = 0;
+ crop.Y = 0;
+ crop.X2 = preset.TargetWidth;
+ crop.Y2 = preset.TargetHeight;
+ }
+
+ // stored
+ if (_xml.DocumentElement != null && _xml.DocumentElement.ChildNodes.Count == config.presets.Count)
+ {
+ XmlNode xmlNode = _xml.DocumentElement.ChildNodes[i];
+
+ int xml_x = Convert.ToInt32(xmlNode.Attributes["x"].Value);
+ int xml_y = Convert.ToInt32(xmlNode.Attributes["y"].Value);
+ int xml_x2 = Convert.ToInt32(xmlNode.Attributes["x2"].Value);
+ int xml_y2 = Convert.ToInt32(xmlNode.Attributes["y2"].Value);
+
+ // only use xml values if image is the same and different from defaults (document is stored inbetween image upload and cropping)
+ //if (xml_x2 - xml_x != preset.TargetWidth || xml_y2 - xml_y != preset.TargetHeight)
+ //fileDate == imageInfo.DateStamp && (
+
+ if (crop.X != xml_x || crop.X2 != xml_x2 || crop.Y != xml_y || crop.Y2 != xml_y2)
+ {
+ crop.X = xml_x;
+ crop.Y = xml_y;
+ crop.X2 = xml_x2;
+ crop.Y2 = xml_y2;
+ }
+ }
+
+ sbJson.Append(",\"value\":{" + String.Format("\"x\":{0},\"y\":{1},\"x2\":{2},\"y2\":{3}", crop.X, crop.Y, crop.X2, crop.Y2) + "}}");
+ sbRaw.Append(String.Format("{0},{1},{2},{3}", crop.X, crop.Y, crop.X2, crop.Y2));
+
+ if (i < config.presets.Count - 1)
+ {
+ sbJson.Append(",");
+ sbRaw.Append(";");
}
}
- sbJson.Append(",\"value\":{" + String.Format("\"x\":{0},\"y\":{1},\"x2\":{2},\"y2\":{3}", crop.X, crop.Y, crop.X2, crop.Y2) + "}}");
- sbRaw.Append(String.Format("{0},{1},{2},{3}", crop.X, crop.Y, crop.X2, crop.Y2));
+ sbJson.Append("]}");
+
+ hdnJson.Value = sbJson.ToString();
+ //hdnJson.ID = String.Format("json_{0}", propertyId);
+ hdnRaw.Value = sbRaw.ToString();
+ //hdnRaw.ID = String.Format("raw_{0}", propertyId);
+
+ Controls.Add(imgImage);
+
+ Controls.Add(hdnJson);
+ Controls.Add(hdnRaw);
+
+ string imageCropperInitScript =
+ "initImageCropper('" +
+ imgImage.ClientID + "', '" +
+ hdnJson.ClientID + "', '" +
+ hdnRaw.ClientID +
+ "');";
+
+ Page.ClientScript.RegisterStartupScript(GetType(), ClientID + "_imageCropper", imageCropperInitScript, true);
+ Page.ClientScript.RegisterClientScriptBlock(Resources.json2Script.GetType(), "json2Script", Resources.json2Script, true);
+ Page.ClientScript.RegisterClientScriptBlock(Resources.jCropCSS.GetType(), "jCropCSS", Resources.jCropCSS);
+ Page.ClientScript.RegisterClientScriptBlock(Resources.jCropScript.GetType(), "jCropScript", Resources.jCropScript, true);
+ Page.ClientScript.RegisterClientScriptBlock(Resources.imageCropperScript.GetType(), "imageCropperScript", Resources.imageCropperScript, true);
- if (i < config.presets.Count - 1)
- {
- sbJson.Append(",");
- sbRaw.Append(";");
- }
}
- sbJson.Append("]}");
-
- hdnJson.Value = sbJson.ToString();
- //hdnJson.ID = String.Format("json_{0}", propertyId);
- hdnRaw.Value = sbRaw.ToString();
- //hdnRaw.ID = String.Format("raw_{0}", propertyId);
-
- Controls.Add(imgImage);
-
- Controls.Add(hdnJson);
- Controls.Add(hdnRaw);
-
- string imageCropperInitScript =
- "initImageCropper('" +
- imgImage.ClientID + "', '" +
- hdnJson.ClientID + "', '" +
- hdnRaw.ClientID +
- "');";
-
- Page.ClientScript.RegisterStartupScript(GetType(), ClientID + "_imageCropper", imageCropperInitScript, true);
- Page.ClientScript.RegisterClientScriptBlock(Resources.json2Script.GetType(), "json2Script", Resources.json2Script, true);
- Page.ClientScript.RegisterClientScriptBlock(Resources.jCropCSS.GetType(), "jCropCSS", Resources.jCropCSS);
- Page.ClientScript.RegisterClientScriptBlock(Resources.jCropScript.GetType(), "jCropScript", Resources.jCropScript, true);
- Page.ClientScript.RegisterClientScriptBlock(Resources.imageCropperScript.GetType(), "imageCropperScript", Resources.imageCropperScript, true);
-
-
base.OnInit(e);
}
-
///
General
"); writer.Write("| Property alias: (eg. 'umbracoFile'): | "); - txtPropertyAlias.RenderControl(writer); - writer.Write(" |
| Property alias: | "); + writer.Write(""); + this.imagePropertyTypePicker.RenderControl(writer); + this.imagePropertyRequiredFieldValidator.RenderControl(writer); + writer.Write(@" | +
| Save crop images (/media/(imageid)/(filename)_(cropname).jpg): | "); chkGenerateCrops.RenderControl(writer); litQuality.RenderControl(writer); @@ -383,9 +402,7 @@ namespace umbraco.editorControls.imagecropper //_generateButton.RenderControl(writer); //_vsErrors.RenderControl(writer); - //_revName.RenderControl(writer); - - + //_revName.RenderControl(writer); } public string Configuration |