2010-02-08 02:22:42 +00:00
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Text ;
using umbraco.uicontrols.TreePicker ;
using umbraco.interfaces ;
2010-03-01 12:55:01 +00:00
using System.Web.UI ;
using umbraco.presentation ;
2010-02-08 02:22:42 +00:00
namespace umbraco.editorControls
{
/// <summary>
/// A base tree picker class that has all of the functionality built in for an IDataEditor
/// </summary>
2013-10-21 18:36:46 +11:00
[Obsolete("IDataType and all other references to the legacy property editors are no longer used this will be removed from the codebase in future versions")]
2010-02-08 02:22:42 +00:00
public abstract class BaseTreePickerEditor : BaseTreePicker , IDataEditor
{
interfaces . IData _data ;
protected int StoredItemId = - 1 ;
public BaseTreePickerEditor ( )
: base ( ) { }
public BaseTreePickerEditor ( IData Data )
: base ( )
{
_data = Data ;
}
private void StoreItemId ( IData Data )
{
if ( _data ! = null & & _data . Value ! = null & & ! String . IsNullOrEmpty ( _data . Value . ToString ( ) ) )
{
int . TryParse ( _data . Value . ToString ( ) , out StoredItemId ) ;
}
}
protected override void OnInit ( EventArgs e )
{
StoreItemId ( _data ) ;
2011-01-20 13:56:20 -01:00
// zb-00024 #299260 : see the loooong comments in OnLoad
// setting the value here seems OK but use this.Value to ensure
// that the hidden control exists
this . Value = StoredItemId ! = - 1 ? StoredItemId . ToString ( ) : "" ;
2010-02-08 02:22:42 +00:00
base . OnInit ( e ) ;
}
protected override void OnLoad ( EventArgs e )
{
base . OnLoad ( e ) ;
2010-03-01 12:55:01 +00:00
//need to check if this is an async postback in live editing, because if it is, we need to set the value
2013-09-24 19:27:13 +10:00
//SD: Since live editing is removed I don't really think this is at all necessary but it's still here.
if ( ( ScriptManager . GetCurrent ( Page ) . IsInAsyncPostBack ) | | ! Page . IsPostBack )
2010-02-08 02:22:42 +00:00
{
ItemIdValue . Value = StoredItemId ! = - 1 ? StoredItemId . ToString ( ) : "" ;
}
2011-01-20 13:56:20 -01:00
// zb-00024 #299260 : support postback
// on postback ItemIdValue.Value is restored by LoadPostData
// on non-postback it is initialized by the code above
// w/RCC when clicking on 'edit' it is not initialized
// StoredItemId is initialized in OnInit with whatever comes from the
// database, or from what the RCC decides we need to display--but when
// we changes something in the web page, it is handled by LoadPostData
// RCC 'edit':
// ItemIdValue.Value has no value, or a wrong value, which we should ignore
// StoredItemId is initialized with the right value in RCC code
// so we'd need to set ItemIdValue.Value from it
// but if we do it in prerender then we copy over the /old/ StoredItemIt
// value which was the one before we saved... because we don't refresh it
// when we update
// and if we refresh it here we are in trouble because we overwrite what
// comes from the form and we can't actually change the value anymore
// so we should change it /once/ the ItemIdValue.Value changes have been
// akn
// the viewed image ID is set in mediaChoose onPreRender from
// ItemIdValue.Value so we really want it to have a value!
2010-02-08 02:22:42 +00:00
}
#region IDataField Members
public System . Web . UI . Control Editor { get { return this ; } }
public virtual bool TreatAsRichTextEditor
{
get { return false ; }
}
public bool ShowLabel
{
get
{
return true ;
}
}
public void Save ( )
{
if ( ItemIdValue . Value . Trim ( ) ! = "" )
2013-08-12 16:20:32 +02:00
_data . Value = int . Parse ( ItemIdValue . Value . Trim ( ) ) ;
2010-02-08 02:22:42 +00:00
else
_data . Value = null ;
}
#endregion
}
}