diff --git a/components/editorControls/KeyValuePrevalueEditor.cs b/components/editorControls/KeyValuePrevalueEditor.cs index 376738a335..3bb9b94e94 100644 --- a/components/editorControls/KeyValuePrevalueEditor.cs +++ b/components/editorControls/KeyValuePrevalueEditor.cs @@ -5,7 +5,10 @@ using System.Web.UI.WebControls; using umbraco.BusinessLogic; using umbraco.DataLayer; +using System.Collections.Generic; + +[assembly: System.Web.UI.WebResource("umbraco.editorControls.KeyValuePrevalueEditor.js", "text/js")] namespace umbraco.editorControls { /// @@ -17,6 +20,7 @@ namespace umbraco.editorControls // UI controls public System.Web.UI.WebControls.DropDownList _dropdownlist; public TextBox _textbox; + private TextBox _tbhidden; public umbraco.uicontrols.PropertyPanel pp1 = new umbraco.uicontrols.PropertyPanel(); public umbraco.uicontrols.PropertyPanel pp2 = new umbraco.uicontrols.PropertyPanel(); @@ -56,10 +60,15 @@ namespace umbraco.editorControls _textbox = new TextBox(); _textbox.ID = "AddValue"; + _tbhidden = new TextBox(); + _tbhidden.Attributes.Add("style", "display:none;"); + _tbhidden.CssClass = "valuesHiddenInput"; + // put the childcontrols in context - ensuring that // the viewstate is persisted etc. this.Controls.Add(_dropdownlist); this.Controls.Add(_textbox); + this.Controls.Add(_tbhidden); _dropdownlist.Items.Add(DBTypes.Date.ToString()); _dropdownlist.Items.Add(DBTypes.Integer.ToString()); @@ -70,6 +79,14 @@ namespace umbraco.editorControls protected override void OnInit(EventArgs e) { base.OnInit(e); + + System.Web.UI.Page page = (System.Web.UI.Page)System.Web.HttpContext.Current.Handler; + + + page.ClientScript.RegisterClientScriptInclude( + "umbraco.editorControls.KeyValuePrevalueEditor.js", + page.ClientScript.GetWebResourceUrl(typeof(KeyValuePrevalueEditor), "umbraco.editorControls.KeyValuePrevalueEditor.js")); + } protected override void OnLoad(EventArgs e) @@ -96,7 +113,37 @@ namespace umbraco.editorControls public void Save() { _datatype.DBType = (cms.businesslogic.datatype.DBTypes)Enum.Parse(typeof(cms.businesslogic.datatype.DBTypes), _dropdownlist.SelectedValue, true); - // If the add new prevalue textbox is filled out - add the value to the collection. + + //changes in name and sortorder + if (!string.IsNullOrEmpty(_tbhidden.Text)) + { + int so = 0; + foreach (string row in _tbhidden.Text.Split(';')) + { + if (!string.IsNullOrEmpty(row)) + { + + int id = 0; + + if (row.Split('|').Length == 2 && int.TryParse(row.Split('|')[0], out id) && row.Split('|')[1].Length > 0) + { + + IParameter[] SqlParams = new IParameter[] { + SqlHelper.CreateParameter("@value",row.Split('|')[1]), + SqlHelper.CreateParameter("@sortorder",so), + SqlHelper.CreateParameter("@id",id)}; + SqlHelper.ExecuteNonQuery("update cmsDataTypePreValues set [value] = @value, sortorder = @sortorder where id = @id", SqlParams); + + } + + so++; + } + } + + _tbhidden.Text = ""; + } + + // If the add new prevalue textbox is filled out - add the value to the collection. if (_textbox.Text != "") { IParameter[] SqlParams = new IParameter[] { @@ -115,13 +162,14 @@ namespace umbraco.editorControls _dropdownlist.RenderControl(writer); writer.Write("
"); - SortedList _prevalues = Prevalues; + List> _prevalues = PrevaluesAsKeyValuePairList; if (_prevalues.Count > 0) { - writer.Write("
"); + writer.Write("
"); writer.Write(""); - foreach (object key in _prevalues.Keys) { - writer.Write(""); + foreach (KeyValuePair item in _prevalues) + { + writer.Write(""); } writer.Write("
TextValue
" + _prevalues[key].ToString() + " " + key + "" + ui.Text("delete") + "
" + item.Value + " " + item.Key.ToString() + "" + ui.Text("delete") + " sort

"); } @@ -129,14 +177,16 @@ namespace umbraco.editorControls writer.Write("
" + ui.Text("addPrevalue") + "
"); _textbox.RenderControl(writer); writer.Write("
"); - - + + _tbhidden.RenderControl(writer); + } public SortedList Prevalues { get { + SortedList retval = new SortedList(); IRecordsReader dr = SqlHelper.ExecuteReader( "Select id, [value] from cmsDataTypePreValues where DataTypeNodeId = " @@ -148,5 +198,23 @@ namespace umbraco.editorControls return retval; } } + + public List> PrevaluesAsKeyValuePairList + { + get + { + + List> items = new List>(); + + IRecordsReader dr = SqlHelper.ExecuteReader( + "Select id, [value] from cmsDataTypePreValues where DataTypeNodeId = " + + _datatype.DataTypeDefinitionId + " order by sortorder"); + + while (dr.Read()) + items.Add(new KeyValuePair(dr.GetInt("id"), dr.GetString("value"))); + dr.Close(); + return items; + } + } } } diff --git a/components/editorControls/KeyValuePrevalueEditor.js b/components/editorControls/KeyValuePrevalueEditor.js new file mode 100644 index 0000000000..0be271bbd3 --- /dev/null +++ b/components/editorControls/KeyValuePrevalueEditor.js @@ -0,0 +1,113 @@ + +jQuery(document).ready(function () { + + jQuery("#prevalues .text").valuesInlineEdit(); + + jQuery("#prevalues tbody").sortable({ + handle: '.handle', + update: function () { + + ResetValues(); + + } + }); +}); + + +function ResetValues() { + + var val = ""; + + jQuery("#prevalues .row").each(function () { + + var text = jQuery(".text", this).html(); + var value = jQuery(".value", this).html(); + + + val += value + "|" + text + ";"; + + }); + + jQuery(".valuesHiddenInput").val(val); +} + +//inline edit +(function ($) { + + $.fn.valuesInlineEdit = function (options) { + + options = $.extend({ + hover: 'hover', + value: '', + save: '', + placeholder: 'Click to edit' + }, options); + + return $.each(this, function () { + $.valuesInlineEdit(this, options); + }); + } + + $.valuesInlineEdit = function (obj, options) { + + var self = $(obj), + placeholderHtml = '' + options.placeholder + ''; + + self.value = function (newValue) { + if (arguments.length) { + self.data('value', $(newValue).hasClass('inlineEdit-placeholder') ? '' : newValue); + } + return self.data('value'); + } + + self.value($.trim(self.text()) || options.value); + + self.bind('click', function (event) { + var $this = $(event.target); + + if ($this.is(self[0].tagName) || $this.hasClass('inlineEdit-placeholder')) { + self + .html('') + .find('input') + .bind('blur', function () { + if ($this.children('input').val().length > 0) { + + try { + self.value($this.children('input').val()); + + + + } catch (err) { } + + + } + else { + self.value('Click to edit'); + } + if (self.timer) { + window.clearTimeout(self.timer); + } + self.timer = window.setTimeout(function () { + self.html(self.value() || placeholderHtml); + self.removeClass(options.hover); + ResetValues(); + }, 200); + }) + .focus(); + } + }) + .hover( + function () { + $(this).addClass(options.hover); + }, + function () { + $(this).removeClass(options.hover); + } + ); + + if (!self.value()) { + self.html($(placeholderHtml)); + } + } + +})(jQuery); \ No newline at end of file diff --git a/components/editorControls/umbraco.editorControls.csproj b/components/editorControls/umbraco.editorControls.csproj index c9ce3321f7..c1dc628513 100644 --- a/components/editorControls/umbraco.editorControls.csproj +++ b/components/editorControls/umbraco.editorControls.csproj @@ -416,6 +416,7 @@ +