DO NOT DOWNLOAD, STABLE RELEASE AVAILABLE ON THE RELEASES TAB

Fixed Python editor, Fixed last IE bug with Code editor

[TFS Changeset #59521]
This commit is contained in:
Shandem
2009-09-28 13:06:10 +00:00
parent 9fc25857e4
commit 565fa7864d
15 changed files with 2795 additions and 201 deletions

View File

@@ -150,12 +150,7 @@ namespace umbraco.uicontrols {
protected string RenderBasicEditor()
{
string jsEventCode = @"
if (navigator.userAgent.match('MSIE')) {
//addEvent(m_textEditor, ""select"", function() { storeCaret(this); });
//addEvent(m_textEditor, ""click"", function() { storeCaret(this); });
//addEvent(m_textEditor, ""keyup"", function() { storeCaret(this); });
}
string jsEventCode = @"
var m_textEditor = document.getElementById('" + this.ClientID + @"');
tab.watch('" + this.ClientID + @"');
";
@@ -164,6 +159,9 @@ namespace umbraco.uicontrols {
protected string RenderCodeEditor()
{
//get the client dependency url for the file so that it's compressed
var baseFileSource = ClientDependencyLoader.GetCompositeUrl(new string[]
{ GlobalSettings.ClientPath + "/CodeMirror/js/CoreCombined.js" }, ClientDependencyType.Javascript);
string[] parserFiles = new string[] { "tokenizejavascript.js", "parsejavascript.js" };
string[] cssFile = new string[] { "jscolors.css", "umbracoCustom.css" };
@@ -188,28 +186,26 @@ namespace umbraco.uicontrols {
break;
case EditorType.HTML:
parserFiles = new string[] { "parsexml.js", "parsecss.js", "tokenizejavascript.js", "parsejavascript.js", "parsehtmlmixed.js" };
cssFile = new string[] { "xmlcolors.css", "jscolors.css", "csscolors", "umbracoCustom.css" };
cssFile = new string[] { "xmlcolors.css", "jscolors.css", "csscolors.css", "umbracoCustom.css" };
break;
}
var jsEventCode = @"
var textarea = document.getElementById('" + CodeTextBox.ClientID + @"');
var codeEditor = CodeMirror.fromTextArea(textarea, {
basefiles: ['" + baseFileSource + @"'],
width: ""100%"",
height: ""100%"",
tabMode: ""shift"",
textWrapping: false,
lineNumbers: true,
parserfile: [" + string.Join(",",
parserFiles
.Select(x => string.Format(@"""{0}""", x))
.ToArray()) + @"],
stylesheet: [" + string.Join(",",
parserfile: ['" + ClientDependencyLoader.GetCompositeUrl(parserFiles, ClientDependencyType.Javascript) + @"'],
stylesheet: ['" + ClientDependencyLoader.GetCompositeUrl(
cssFile
.Select(x => string.Format(@"""{0}""", GlobalSettings.ClientPath + @"/CodeMirror/css/" + x))
.ToArray()) + @"],
.Select(x => GlobalSettings.ClientPath + @"/CodeMirror/css/" + x)
.ToArray(), ClientDependencyType.Css) + @"'],
path: """ + GlobalSettings.ClientPath + @"/CodeMirror/js/"",
content: textarea.value,
autoMatchParens: false,"

View File

@@ -1,4 +1,4 @@
<clientDependency isDebugMode="true ">
<clientDependency isDebugMode="true">
<fileRegistration defaultProvider="PageHeaderProvider" fileDependencyExtensions="js,css" enableCompositeFiles="true">
<providers>
<add name="PageHeaderProvider" type="ClientDependency.Core.FileRegistration.Providers.PageHeaderProvider, ClientDependency.Core" />

View File

@@ -1465,6 +1465,7 @@
<Content Include="umbraco_client\CodeMirror\css\umbracoCustom.css" />
<Content Include="umbraco_client\CodeMirror\css\xmlcolors.css" />
<Content Include="umbraco_client\CodeMirror\js\codemirror.js" />
<Content Include="umbraco_client\CodeMirror\js\CoreCombined.js" />
<Content Include="umbraco_client\CodeMirror\js\editor.js" />
<Content Include="umbraco_client\CodeMirror\js\highlight.js" />
<Content Include="umbraco_client\CodeMirror\js\mirrorframe.js" />

View File

@@ -15,8 +15,8 @@
<umb:JsInclude ID="JsInclude8" runat="server" FilePath="Tree/tree_component.min.js" PathNameAlias="UmbracoClient" Priority="11" />
<%--<umb:JsInclude ID="JsInclude8" runat="server" FilePath="Tree/tree_component.js" PathNameAlias="UmbracoClient" Priority="11" />--%>
<umb:JsInclude ID="JsInclude9" runat="server" FilePath="Tree/NodeDefinition.js" PathNameAlias="UmbracoClient" Priority="12" />
<%--<umb:JsInclude ID="JsInclude10" runat="server" FilePath="Tree/UmbracoTree.min.js" PathNameAlias="UmbracoClient" Priority="13" />--%>
<umb:JsInclude ID="JsInclude10" runat="server" FilePath="Tree/UmbracoTree.js" PathNameAlias="UmbracoClient" Priority="13" />
<umb:JsInclude ID="JsInclude10" runat="server" FilePath="Tree/UmbracoTree.min.js" PathNameAlias="UmbracoClient" Priority="13" />
<%--<umb:JsInclude ID="JsInclude10" runat="server" FilePath="Tree/UmbracoTree.js" PathNameAlias="UmbracoClient" Priority="13" />--%>
<script type="text/javascript">

View File

@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.3082
// Runtime Version:2.0.50727.3074
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.

View File

@@ -4,6 +4,7 @@
<%@ Register TagPrefix="cc1" Namespace="umbraco.uicontrols" Assembly="controls" %>
<asp:Content ID="cp0" runat="server" ContentPlaceHolderID="head">
<script type="text/javascript">
function pythonInsertValue(theValue) {
insertAtCaret(document.getElementById('pythonSource'), theValue)
@@ -15,37 +16,31 @@
function showError() {
var id = "#<%=errorHolder.ClientID%>";
if (jQuery(id).is(":visible")) {
if (jQuery(id).is(":visible")) {
jQuery(id).hide();
jQuery('#showErrorLink').html('<b>Show error</b> <img src="../images/arrowForward.gif" align="absmiddle" border="0"/><br/><br/>');
}
else {
jQuery(id).show();
jQuery('#showErrorLink').html('<b>Hide error</b> <img src="../images/arrowDown.gif" align="absmiddle" border="0"/><br/>');
}
}
</script>
</asp:Content>
<asp:Content ID="cp1" runat="server" ContentPlaceHolderID="body">
<cc1:UmbracoPanel ID="UmbracoPanel1" runat="server" Text="Edit xsl" Height="300"
Width="500">
<cc1:Pane ID="Pane1" runat="server">
<cc1:UmbracoPanel ID="UmbracoPanel1" runat="server" Text="Edit xsl" Height="300" Width="600">
<cc1:Pane ID="Pane1" runat="server" Style="margin-bottom: 10px;">
<cc1:PropertyPanel ID="pp_filename" Text="Filename" runat="server">
<asp:TextBox ID="pythonFileName" runat="server" Width="400" CssClass="guiInputText"></asp:TextBox>
</cc1:PropertyPanel>
<cc1:PropertyPanel ID="pp_testing" runat="server" Text="Skip testing (ignore errors)">
<asp:CheckBox ID="SkipTesting" runat="server"></asp:CheckBox>
</cc1:PropertyPanel>
<br />
<asp:Literal ID="closeErrorMessage" runat="server" Visible="false" EnableViewState="false">
<a id="showErrorLink" href="javascript:showError()"><b>Hide error</b> <img src="../images/arrowDown.gif" align="absmiddle" border="0"/></a>
</asp:Literal>
<asp:Panel ID="errorHolder" runat="server" Visible="False" EnableViewState="false">
<span style="color: red">
<cc1:PropertyPanel ID="pp_error" runat="server">
<div runat="server" id="errorHolder" visible="false" enableviewstate="false" class="error">
<a id="showErrorLink" href="javascript:showError()">
<p><b>Hide error</b></p>
</a>
<br />
<asp:Label ID="pythonError" runat="server"></asp:Label>
</span>
</asp:Panel>
</div>
</cc1:PropertyPanel>
<cc1:CodeArea ID="pythonSource" CodeBase="Python" AutoResize="true" OffSetX="47" OffSetY="55" runat="server" />
</cc1:Pane>
</cc1:UmbracoPanel>

View File

@@ -47,11 +47,11 @@ namespace umbraco.cms.presentation.developer
{
base.speechBubble(speechBubbleIcon.error, ui.Text("errors", "pythonErrorHeader", base.getUser()), ui.Text("errors", "pythonErrorText", base.getUser()));
errorHolder.Visible = true;
closeErrorMessage.Visible = true;
//closeErrorMessage.Visible = true;
errorHolder.Attributes.Add("style", "height: 250px; overflow: auto; border: 1px solid CCC; padding: 5px;");
errorMessage = errorPython.ToString();
pythonError.Text = errorMessage.Replace("\n", "<br/>\n");
closeErrorMessage.Visible = true;
//closeErrorMessage.Visible = true;
}
}
if (errorMessage == "")

View File

@@ -68,13 +68,13 @@ namespace umbraco.cms.presentation.developer {
protected global::System.Web.UI.WebControls.CheckBox SkipTesting;
/// <summary>
/// closeErrorMessage control.
/// pp_error control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Literal closeErrorMessage;
protected global::umbraco.uicontrols.PropertyPanel pp_error;
/// <summary>
/// errorHolder control.
@@ -83,7 +83,7 @@ namespace umbraco.cms.presentation.developer {
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Panel errorHolder;
protected global::System.Web.UI.HtmlControls.HtmlGenericControl errorHolder;
/// <summary>
/// pythonError control.

View File

@@ -75,8 +75,7 @@
</asp:Content>
<asp:Content ContentPlaceHolderID="body" runat="server" ID="cp1">
<cc1:UmbracoPanel ID="UmbracoPanel1" runat="server" Text="Edit xsl" hasMenu="true"
Height="300" Width="600">
<cc1:UmbracoPanel ID="UmbracoPanel1" runat="server" Text="Edit xsl" hasMenu="true" Height="300" Width="600">
<cc1:Pane ID="Pane1" runat="server" Style="margin-bottom: 10px;">
<cc1:PropertyPanel ID="pp_filename" runat="server" Text="Filename">
<asp:TextBox ID="xsltFileName" runat="server" Width="300" CssClass="guiInputText"></asp:TextBox>
@@ -85,8 +84,7 @@
<asp:CheckBox ID="SkipTesting" runat="server"></asp:CheckBox>
</cc1:PropertyPanel>
<cc1:PropertyPanel ID="pp_errorMsg" runat="server">
<div id="errorDiv" style="display: none;" class="error">
hest</div>
<div id="errorDiv" style="display: none;" class="error">test</div>
</cc1:PropertyPanel>
<cc1:CodeArea ID="editorSource" CodeBase="XML" ClientSaveMethod="doSubmit" runat="server" AutoResize="true" OffSetX="47" OffSetY="55" />
</cc1:Pane>

View File

@@ -52,17 +52,10 @@ Umbraco.Sys.registerNamespace("Umbraco.Controls.CodeEditor");
else {
this._editor.win.document.body.focus(); //need to restore the focus to the editor body
//if the saved selection (IE only) is not null, then
//reselect the selection there is one, otherwise, expand the non-selection by 1
//I know, this is wierd but it's an IE issue and this fixes it.
//if the saved selection (IE only) is not null, then
if (this._cmSave != null) {
if (this._cmSave.text.length > 0) {
this._cmSave.select();
}
else {
this._cmSave.expand("character");
}
}
this._editor.selectLines(this._cmSave.start.line, this._cmSave.start.character, this._cmSave.end.line, this._cmSave.end.character);
}
var selection = this._editor.selection();
var replace = (arg3) ? open + arg3 : open; //concat open and arg3, if arg3 specified
@@ -100,7 +93,7 @@ Umbraco.Sys.registerNamespace("Umbraco.Controls.CodeEditor");
/// in the editors so that when the selections are lost (i.e. the user types in a different text box
/// we'll need to restore the selection when they return focus
/// </summary>
if (navigator.userAgent.match('MSIE')) {
if (document.all) {
var _this = this;
if (this._editor == null) {
function storeCaret(editEl) {
@@ -111,13 +104,13 @@ Umbraco.Sys.registerNamespace("Umbraco.Controls.CodeEditor");
this._control.click( function() {storeCaret(this)} );
this._control.keyup( function() {storeCaret(this)} );
}
else {
//when the editor loses focus, save the current selection
this._editor.win.document.body.onblur = function()
{
_this._cmSave = _this._editor.win.document.selection.createRange();
return true;
};
else {
this._editor.options.cursorActivity = function() {
_this._cmSave = {
start: _this._editor.cursorPosition(true), //save start position
end: _this._editor.cursorPosition(false) //save end position
}
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -81,13 +81,10 @@ var CodeMirror = (function(){
var nextNum = 1, barWidth = null;
function sizeBar() {
if (!frame.offsetWidth || !win.Editor) {
for (var cur = frame; cur.parentNode; cur = cur.parentNode) {
if (cur != document) {
clearInterval(sizeInterval);
return;
}
}
for (var root = frame; root.parentNode; root = root.parentNode);
if (root != document || !win.Editor) {
clearInterval(sizeInterval);
return;
}
if (nums.offsetWidth != barWidth) {
@@ -175,10 +172,14 @@ var CodeMirror = (function(){
getCode: function() {return this.editor.getCode();},
setCode: function(code) {this.editor.importCode(code);},
selection: function() {return this.editor.selectedText();},
selection: function() {this.focusIfIE(); return this.editor.selectedText();},
reindent: function() {this.editor.reindent();},
reindentSelection: function() {this.editor.reindentSelection(null);},
reindentSelection: function() {this.focusIfIE(); this.editor.reindentSelection(null);},
focusIfIE: function() {
// in IE, a lot of selection-related functionality only works when the frame is focused
if (this.win.select.ie_selection) this.focus();
},
focus: function() {
this.win.focus();
if (this.editor.selectionSnapshot) // IE hack
@@ -206,10 +207,7 @@ var CodeMirror = (function(){
setParser: function(name) {this.editor.setParser(name);},
cursorPosition: function(start) {
if (this.win.select.ie_selection) this.focus();
return this.editor.cursorPosition(start);
},
cursorPosition: function(start) {this.focusIfIE(); return this.editor.cursorPosition(start);},
firstLine: function() {return this.editor.firstLine();},
lastLine: function() {return this.editor.lastLine();},
nextLine: function(line) {return this.editor.nextLine(line);},

View File

@@ -53,7 +53,7 @@ Umbraco.Sys.registerNamespace("Umbraco.Controls");
_showContext: true,
_isEditMode: false,
_isDialog: false,
_isDebug: true, //set to true to enable alert debugging
_isDebug: false, //set to true to enable alert debugging
_loadedApps: [], //stores the application names that have been loaded to track which JavaScript code has been inserted into the DOM
_serviceUrl: "", //a path to the tree client service url
_dataUrl: "", //a path to the tree data service url

View File

@@ -1,124 +1,50 @@
Umbraco.Sys.registerNamespace("Umbraco.Controls"); (function($) {
$.fn.UmbracoTree = function(opts) { return this.each(function() { var conf = $.extend({ jsonFullMenu: null, jsonInitNode: null, appActions: null, uiKeys: null, app: "", showContext: true, isDialog: false, treeType: "standard", umb_clientFolderRoot: "/umbraco_client", recycleBinId: -20 }, opts); new Umbraco.Controls.UmbracoTree().init($(this), conf); }); }; $.fn.UmbracoTreeAPI = function() { return $(this).data("UmbracoTree") == null ? null : $(this).data("UmbracoTree"); }; Umbraco.Controls.UmbracoTree = function() {
return { _actionNode: new Umbraco.Controls.NodeDefinition(), _activeTreeType: "content", _recycleBinId: -20, _umb_clientFolderRoot: "/umbraco_client", _fullMenu: null, _initNode: null, _menuActions: null, _tree: null, _uiKeys: null, _container: null, _app: null, _showContext: true, _isDialog: false, _isDebug: false, _loadedApps: [], _serviceUrl: "", _dataUrl: "", _treeType: "standard", _treeClass: "umbTree", _currenAJAXRequest: false, addEventHandler: function(fnName, fn) { $(this).bind(fnName, fn); }, removeEventHandler: function(fnName, fn) { $(this).unbind(fnName, fn); }, init: function(jItem, opts) { this._init(opts.jsonFullMenu, opts.jsonInitNode, jItem, opts.appActions, opts.uiKeys, opts.app, opts.showContext, opts.isDialog, opts.treeType, opts.serviceUrl, opts.dataUrl, opts.umb_clientFolderRoot, opts.recycleBinId); jItem.addClass(this._treeClass); jItem.data("UmbracoTree", this); }, setRecycleBinNodeId: function(id) { this._recycleBinId = id; }, clearTreeCache: function() { this._debug("clearTreeCache..."); for (var a in this._loadedApps) { this._debug("clearTreeCache: " + this._loadedApps[a]); this._container.data("tree_" + this._loadedApps[a], null); } }, rebuildTree: function(app) {
this._debug("rebuildTree"); if (this._app == null || (this._app.toLowerCase() == app.toLowerCase())) { this._debug("not rebuilding"); return; }
else { this._app = app; }
$("div").remove(".tree-default-context"); this._tree.destroy(); this._container.hide(); var _this = this; var saveData = this._container.data("tree_" + app); if (saveData != null) {
this._debug("rebuildTree: rebuilding from cache: app = " + app); this._initNode = saveData.d; this._tree = $.tree_create(); this._tree.init(this._container, this._getInitOptions()); this._configureNodes(this._container.find("li"), true); var lastSelected = saveData.selected != null ? $(saveData.selected[0]).attr("id") : null; if (lastSelected != null) { var _this = this; var foundHandler = function(EV, node) { _this.removeEventHandler("syncFound", foundHandler); this._debug("rebuildTree: node synced, selecting node..."); _this.selectNode(node, false, true); this._container.show(); }; this._debug("rebuildTree: syncing to last selected: " + lastSelected); this.addEventHandler("syncFound", foundHandler); this.setActiveTreeType($(saveData.selected[0]).attr("umb:type")); this.syncTree(lastSelected); }
else { this._container.show(); }
return;
}
var parameters = "{'app':'" + app + "','showContextMenu':'" + this._showContext + "', 'isDialog':'" + this._isDialog + "'}"
this._currentAJAXRequest = true; $.ajax({ type: "POST", url: this._serviceUrl, data: parameters, contentType: "application/json; charset=utf-8", dataType: "json", success: function(msg) {
msg = msg.d; if ($.inArray(msg.app, _this._loadedApps) == -1) { _this._debug("loading js for app: " + msg.app); _this._loadedApps.push(msg.app); _this._container.after("<script>" + msg.js + "</script>"); }
_this._initNode = eval(msg.json); _this._tree = $.tree_create(); _this._tree.init(_this._container, _this._getInitOptions()); _this._container.show(); _this._loadChildNodes(_this._container.find("li:first"), null); _this._currentAJAXRequest = false; $(_this).trigger("rebuiltTree", [msg.app]);
}, error: function(e) { _this._debug("rebuildTree: AJAX error occurred"); _this._currentAJAXRequest = false; $(_this).trigger("ajaxError", [{ msg: "rebuildTree"}]); }
});
}, saveTreeState: function(appAlias) {
this._debug("saveTreeState: " + appAlias + " : ajax request? " + this._currentAJAXRequest); if (this._currentAJAXRequest) { this._container.data("tree_" + appAlias, null); return; }
var treeData = this._tree.getJSON(null, ["id", "umb:type", "class"], ["umb:nodedata", "href", "class", "style"]); this._updateJSONNodeState(treeData); this._container.data("tree_" + appAlias, { selected: this._tree.selected, d: treeData });
}, _updateJSONNodeState: function(obj) {
var node = $("li[id='" + obj.attributes.id + "']").filter(function() { return ($(this).attr("umb:type") == obj.attributes["umb:type"]); }); var c = node.attr("class"); if (c != null) { var state = c.indexOf("open") > -1 ? "open" : c.indexOf("closed") > -1 ? "closed" : null; if (state != null) obj.state = state; }
if (obj.children != null) { for (var x in obj.children) { this._updateJSONNodeState(obj.children[x]); } }
}, syncTree: function(path, forceReload) { this._debug("syncTree: " + path + ", " + forceReload); this._syncTree.call(this, path, forceReload, null, null); }, childNodeCreated: function() {
this._debug("childNodeCreated"); var childrenIds = new Array(); this._actionNode.jsNode.find("ul > li").each(function() { childrenIds.push($(this).attr("id")); }); var _this = this; var currId = this._actionNode.nodeId; this.reloadActionNode(true, false, function(success) {
if (success && childrenIds.length > 0) {
var found = false; var actionNode = _this.findNode(currId); if (actionNode) { actionNode.find("ul > li").each(function() { if ($.inArray($(this).attr("id"), childrenIds) == -1) { found = $(this); } }); }
if (found) { _this._debug("childNodeCreated: selecting new child node: " + found.attr("id")); _this.selectNode(found, true, true); $(_this).trigger("newChildNodeFound", [found]); return; }
}
_this._debug("childNodeCreated: could not select new child!");
});
}, moveNode: function(nodeId, parentPath) { this._debug("moveNode"); var old = this.findNode(nodeId); if (old) old.remove(); var newPath = parentPath + "," + nodeId; var _this = this; var foundHandler = function(EV, node) { _this.removeEventHandler("syncFound", foundHandler); _this.selectNode(node, false, true); $(_this).trigger("nodeMoved", [node]); }; this.addEventHandler("syncFound", foundHandler); this.syncTree(newPath); }, copyNode: function(nodeId, parentPath) { this._debug("copyNode"); var originalNode = this.findNode(nodeId); var _this = this; var foundHandler = function(EV, node) { _this.removeEventHandler("syncFound", foundHandler); _this._loadChildNodes(node, null); if (originalNode) _this.selectNode(originalNode, true); $(_this).trigger("nodeCopied", [node]); }; this.addEventHandler("syncFound", foundHandler); this.syncTree(parentPath); }, findNode: function(nodeId, findGlobal) { var _this = this; var branch = this._container.find("li[id='" + nodeId + "']"); if (!findGlobal) branch = branch.filter(function() { return ($(this).attr("umb:type") == _this._activeTreeType); }); var found = branch.length > 0 ? branch : false; this._debug("findNode: " + nodeId + " in '" + this._activeTreeType + "' tree. Found? " + found.length); return found; }, selectNode: function(node, supressEvent, reselect) {
this._debug("selectNode"); var selectedId = this._tree.selected != null ? $(this._tree.selected[0]).attr("id") : null; if (reselect || (selectedId == null || selectedId != node.attr("id"))) {
if (supressEvent) { this._tree.settings.callback.onselect = function() { }; }
this._tree.select_branch(node); var _this = this; this._tree.settings.callback.onselect = function(N, T) { _this.onSelect(N, T) };
}
}, reloadActionNode: function(supressSelect, supressChildReload, callback) {
this._debug("reloadActionNode: supressSelect = " + supressSelect + ", supressChildReload = " + supressChildReload); if (this._actionNode != null && this._actionNode.jsNode != null) {
var nodeParent = this._actionNode.jsNode.parents("li:first"); this._debug("reloadActionNode: found " + nodeParent.length + " parent nodes"); if (nodeParent.length == 1) {
var nodeDef = this._getNodeDef(nodeParent); this._debug("reloadActionNode: loading ajax for node: " + nodeDef.nodeId); var _this = this; var toReplace = $("<li class='last'><a class='loading' href='#'><div>" + (this._tree.settings.lang.loading || "Loading ...") + "</div></a></li>").replaceAll(this._actionNode.jsNode); $.get(this._getUrl(nodeDef.sourceUrl), null, function(msg) {
if (!msg || msg.length == 0) { _this._debug("reloadActionNode: error loading ajax data, performing jsTree refresh"); _this._tree.refresh(); if (callback != null) callback.call(_this, false); return; }
var oFound = null; for (var o in msg) {
if (msg[o].attributes != null && msg[o].attributes.id == _this._actionNode.nodeId) {
oFound = _this._tree.parseJSON(msg[o]); if ($(oFound).attr("umb:type") == _this._actionNode.treeType) { break; }
else { oFound = null; }
}
}
if (oFound != null) {
_this._debug("reloadActionNode: node is refreshed!"); var reloaded = $(oFound).replaceAll(toReplace); _this._configureNodes(reloaded, true); if (!supressSelect) _this.selectNode(reloaded); if (!supressChildReload) { _this._loadChildNodes(reloaded, function() { if (callback != null) callback.call(_this, true); }); }
else { if (callback != null) callback.call(_this, true); }
}
else { _this._debug("reloadActionNode: error finding child node in ajax data, performing jsTree refresh"); _this._tree.refresh(); if (callback != null) callback.call(_this, false); }
}, "json"); return;
}
this._debug("reloadActionNode: error finding parent node, performing jsTree refresh"); this._tree.refresh(); if (callback != null) callback.call(this, false);
}
}, getActionNode: function() { return this._actionNode; }, setActiveTreeType: function(treeType) { this._activeTreeType = treeType; }, onNodeDeleting: function(EV) {
this._debug("onNodeDeleting")
this._tree.close_branch(this._actionNode.jsNode); this._actionNode.jsNode.find("a").attr("class", "loading"); this._actionNode.jsNode.find("a").css("background-image", ""); this._actionNode.jsNode.find("a").html(this._uiKeys['deleting']);
}, onNodeDeleted: function(EV) { this._debug("onNodeDeleted"); this._actionNode.jsNode.find("a").removeClass("loading"); this._tree.close_branch(this._actionNode.jsNode); this._actionNode.jsNode.hide("drop", { direction: "down" }, 400); this._updateRecycleBin(); }, onNodeRefresh: function(EV) { this._debug("onNodeRefresh"); this._loadChildNodes(this._actionNode.jsNode, null); }, onSelect: function(NODE, TREE_OBJ) {
this.setActiveTreeType($(NODE).attr("umb:type")); var js = $(NODE).children("a").attr("href").replace("javascript:", ""); this._debug("onSelect: js: " + js); try { var func = eval(js); if (func != null) { func.call(); } } catch (e) { }
return true;
}, onOpen: function(NODE, TREE_OBJ) { this._debug("onOpen: " + $(NODE).attr("id")); var nodes = $(NODE).find("ul > li"); this._configureNodes(nodes); return true; }, onBeforeOpen: function(NODE, TREE_OBJ) { var nodeDef = this._getNodeDef($(NODE)); this._debug("onBeforeOpen: " + nodeDef.nodeId); this._currentAJAXRequest = true; TREE_OBJ.settings.data.url = this._getUrl(nodeDef.sourceUrl); }, onJSONData: function(DATA, TREE_OBJ) { this._debug("onJSONData"); this._currentAJAXRequest = false; return DATA; }, onChange: function(NODE, TREE_OBJ) {
if (this._treeType == "checkbox") {
var $this = $(NODE).is("li") ? $(NODE) : $(NODE).parent(); if ($this.children("a").hasClass("checked")) $this.children("a").removeClass("checked")
else $this.children("a").addClass("checked");
}
else if (this._treeType == "inheritedcheckbox") {
var $this = $(NODE).is("li") ? $(NODE) : $(NODE).parent(); if ($this.children("a.unchecked").size() == 0) { TREE_OBJ.container.find("a").addClass("unchecked"); }
$this.children("a").removeClass("clicked"); if ($this.children("a").hasClass("checked")) { $this.find("li").andSelf().children("a").removeClass("checked").removeClass("undetermined").addClass("unchecked"); var state = 0; }
else { $this.find("li").andSelf().children("a").removeClass("unchecked").removeClass("undetermined").addClass("checked"); var state = 1; }
$this.parents("li").each(function() {
if (state == 1) {
if ($(this).find("a.unchecked, a.undetermined").size() - 1 > 0) { $(this).parents("li").andSelf().children("a").removeClass("unchecked").removeClass("checked").addClass("undetermined"); return false; }
else $(this).children("a").removeClass("unchecked").removeClass("undetermined").addClass("checked");
}
else {
if ($(this).find("a.checked, a.undetermined").size() - 1 > 0) { $(this).parents("li").andSelf().children("a").removeClass("unchecked").removeClass("checked").addClass("undetermined"); return false; }
else $(this).children("a").removeClass("checked").removeClass("undetermined").addClass("unchecked");
}
});
}
$(this).trigger("nodeClicked", [NODE]);
}, onRightClick: function(NODE, TREE_OBJ, EV) { this._actionNode = this._getNodeDef($(NODE)); this.setActiveTreeType($(NODE).attr("umb:type")); this._debug("onRightClick: menu = " + this._actionNode.menu); $("div").remove(".tree-default-context"); if (this._actionNode.menu != "") { TREE_OBJ.settings.ui.context = this._getContextMenu(this._actionNode.menu); TREE_OBJ.context_menu(); var timeout = null; TREE_OBJ.context.mouseenter(function() { clearTimeout(timeout); }); TREE_OBJ.context.mouseleave(function() { timeout = setTimeout(function() { TREE_OBJ.hide_context(); }, 400); }); this._checkContextMenu(TREE_OBJ); } }, _checkContextMenu: function(TREE_OBJ, count) {
if (count > 20)
return; var isVisible = TREE_OBJ.context.is(":visible"); if (!isVisible) { this._debug("_checkContextMenu - waiting for visible menu"); var _this = this; setTimeout(function() { _this._checkContextMenu(TREE_OBJ, ++count); }, 50); return; }
var offset = TREE_OBJ.context.offset(); var bodyHeight = $("body").innerHeight(); var ctxHeight = TREE_OBJ.context.height(); this._debug("_checkContextMenu - offset top: " + offset.top + ", bodyHeight: " + bodyHeight + ", ctxHeight: " + ctxHeight); var diff = (offset.top + ctxHeight) - bodyHeight; if (diff > 0) { this._debug("_checkContextMenu - Menu needs adjusting, new top: " + diff); TREE_OBJ.context.css("top", (offset.top - diff - 10) + "px"); }
}, _debug: function(strMsg) { if (this._isDebug) { Sys.Debug.trace("UmbracoTree: " + strMsg); } }, _configureNodes: function(nodes, reconfigure) {
var _this = this; if (!reconfigure) { nodes = nodes.not("li[class*='loaded']"); }
this._debug("_configureNodes: " + nodes.length); var rxInput = new RegExp("\\boverlay-\\w+\\b", "gi"); nodes.each(function() {
if (_this._treeType != "standard") { $(this).children("a:first").css("background", ""); return; }
$(this).children("div").remove(); var m = $(this).attr("class").match(rxInput); if (m != null) { for (i = 0; i < m.length; i++) { _this._debug("_configureNodes: adding overlay: " + m[i] + " for node: " + $(this).attr("id")); $(this).children("a:first").before("<div class='overlay " + m[i] + "'></div>"); } }
var txt = $(this).children("a").html(); $(this).children("a").html("<div>" + txt + "</div>"); $(this).addClass("loaded");
});
}, _getNodeDef: function(NODE) { var nodedata = $(NODE).children("a").metadata({ type: 'attr', name: 'umb:nodedata' }); this._debug("_getNodeDef: " + $(NODE).attr("id") + ", " + nodedata.nodeType + ", " + nodedata.source); var def = new Umbraco.Controls.NodeDefinition(); def.updateDefinition(this._tree, $(NODE), $(NODE).attr("id"), $(NODE).find("a > div").html(), nodedata.nodeType, nodedata.source, nodedata.menu, $(NODE).attr("umb:type")); return def; }, _updateRecycleBin: function() { this._debug("_updateRecycleBin BinId: " + this._recycleBinId); var rNode = this.findNode(this._recycleBinId, true); if (rNode) { this._actionNode = this._getNodeDef(rNode); var _this = this; this.reloadActionNode(true, true, function(success) { if (success) { _this.findNode(_this._recycleBinId, true).effect("highlight", {}, 1000); } }); } }, _loadChildNodes: function(liNode, callback) { this._debug("_loadChildNodes: " + liNode); liNode.removeClass("leaf"); this._tree.close_branch(liNode, true); liNode.children("ul:eq(0)").html(""); this._tree.open_branch(liNode, false, callback); }, _syncTree: function(path, forceReload, numPaths, numAsync) {
this._debug("_syncTree"); var paths = path.split(","); var found = null; var foundIndex = null; if (numPaths == null) numPaths = (paths.length - 0); for (var i = 0; i < numPaths; i++) { foundIndex = paths.length - (1 + i); found = this.findNode(paths[foundIndex]); this._debug("_syncTree: finding... " + paths[foundIndex] + " found? " + found); if (found) break; }
if (!found) { this._debug("no node found in path: " + path + " : " + numPaths); $(this).trigger("syncNotFound", [path]); return; }
if (found.attr("id") != paths[paths.length - 1]) {
var _this = this; this._loadChildNodes(found, function(NODE, TREE_OBJ) {
var pathsToSearch = paths.length - (Number(foundIndex) + 1); if (_this.findNode(paths[foundIndex + 1])) { _this._syncTree(path, forceReload, pathsToSearch, (numAsync == null ? numAsync == 1 : ++numAsync)); }
else { _this._debug("node not found in children: " + path + " : " + numPaths); $(this).trigger("syncNotFound", [path]); }
});
}
else {
var doReload = (forceReload && (numAsync == null || numAsync < 1)); this._debug("_syncTree: found! numAsync: " + numAsync + ", forceReload: " + forceReload); if (doReload) { this._actionNode = this._getNodeDef(found); this.reloadActionNode(true, true, null); }
else { if (found.attr("id") != "-1") this.selectNode(found, true); this._configureNodes(found, doReload); }
$(this).trigger("syncFound", [found]);
}
}, _getContextMenu: function(strMenu) {
this._debug("_getContextMenu: " + strMenu); var newMenu = new Array(); for (var i = 0; i < strMenu.length; i++) { var letter = strMenu.charAt(i); var menuItem = this._getMenuItemByLetter(letter); if (menuItem != null) newMenu.push(menuItem); }
return newMenu;
}, _getMenuItemByLetter: function(letter) {
if (letter == ",") return "separator"; for (var m in this._fullMenu) { if (this._fullMenu[m].id == letter) { return this._fullMenu[m]; } }
return null;
}, _init: function(jFullMenu, jInitNode, treeContainer, appActions, uiKeys, app, showContext, isDialog, treeType, serviceUrl, dataUrl, umbClientFolder, recycleBinId) {
this._debug("_init: creating new tree with class/id: " + treeContainer.attr("class") + " / " + treeContainer.attr("id")); this._fullMenu = jFullMenu; this._initNode = jInitNode; this._menuActions = appActions; this._uiKeys = uiKeys; this._app = app; this._showContext = showContext; this._isDialog = isDialog; this._treeType = treeType; this._serviceUrl = serviceUrl; this._dataUrl = dataUrl; this._umb_clientFolderRoot = umbClientFolder; this._recycleBinId = recycleBinId; if (this._menuActions != null) { var _this = this; this._menuActions.addEventHandler("nodeDeleting", function(E) { _this.onNodeDeleting(E) }); this._menuActions.addEventHandler("nodeDeleted", function(E) { _this.onNodeDeleted(E) }); this._menuActions.addEventHandler("nodeRefresh", function(E) { _this.onNodeRefresh(E) }); }
this._container = treeContainer; this._tree = $.tree_create(); this._tree.init(this._container, this._getInitOptions()); if ($.inArray(app, this._loadedApps) == -1) { this._loadedApps.push(app); }
this._loadChildNodes(this._container.find("li:first"), null);
}, _getUrl: function(nodeSource) {
if (nodeSource == null || nodeSource == "") { return this._dataUrl; }
var params = nodeSource.split("?")[1]; return this._dataUrl + "?" + params + "&rnd2=" + Umbraco.Utils.generateRandom();
}, _getInitOptions: function() { this._debug("_getInitOptions"); var _this = this; var options = { data: { type: "json", async: true, url: "", json: this._initNode, async_data: function(NODE) { return null; } }, ui: { dots: false, rtl: false, animation: false, hover_mode: true, theme_path: this._umb_clientFolderRoot + "/Tree/Themes/", theme_name: "umbraco", context: null }, lang: { new_node: "New folder", loading: "<div>" + (this._tree.settings.lang.loading || "Loading ...") + "</div>" }, rules: { metadata: "umb:nodedata", creatable: "none", draggable: "none" }, callback: { onrgtclk: function(N, T, E) { _this.onRightClick(N, T, E) }, beforeopen: function(N, T) { _this.onBeforeOpen(N, T) }, onopen: function(N, T) { _this.onOpen(N, T) }, onselect: function(N, T) { _this.onSelect(N, T) }, onchange: function(N, T) { _this.onChange(N, T) }, onJSONdata: function(D, T) { return _this.onJSONData(D, T) } } }; return options; }
};
}
})(jQuery);
Umbraco.Sys.registerNamespace("Umbraco.Controls");(function($){$.fn.UmbracoTree=function(opts){return this.each(function(){var conf=$.extend({jsonFullMenu:null,jsonInitNode:null,appActions:null,uiKeys:null,app:"",showContext:true,isDialog:false,treeType:"standard",umb_clientFolderRoot:"/umbraco_client",recycleBinId:-20},opts);new Umbraco.Controls.UmbracoTree().init($(this),conf);});};$.fn.UmbracoTreeAPI=function(){return $(this).data("UmbracoTree")==null?null:$(this).data("UmbracoTree");};Umbraco.Controls.UmbracoTree=function(){return{_actionNode:new Umbraco.Controls.NodeDefinition(),_activeTreeType:"content",_recycleBinId:-20,_umb_clientFolderRoot:"/umbraco_client",_fullMenu:null,_initNode:null,_appActions:null,_tree:null,_uiKeys:null,_container:null,_app:null,_showContext:true,_isEditMode:false,_isDialog:false,_isDebug:false,_loadedApps:[],_serviceUrl:"",_dataUrl:"",_treeType:"standard",_treeClass:"umbTree",_currenAJAXRequest:false,addEventHandler:function(fnName,fn){$(this).bind(fnName,fn);},removeEventHandler:function(fnName,fn){$(this).unbind(fnName,fn);},init:function(jItem,opts){this._init(opts.jsonFullMenu,opts.jsonInitNode,jItem,opts.appActions,opts.uiKeys,opts.app,opts.showContext,opts.isDialog,opts.treeType,opts.serviceUrl,opts.dataUrl,opts.umb_clientFolderRoot,opts.recycleBinId);jItem.addClass(this._treeClass);jItem.data("UmbracoTree",this);},setRecycleBinNodeId:function(id){this._recycleBinId=id;},clearTreeCache:function(){this._debug("clearTreeCache...");for(var a in this._loadedApps){this._debug("clearTreeCache: "+this._loadedApps[a]);this._container.data("tree_"+this._loadedApps[a],null);}},toggleEditMode:function(enable){this._debug("Edit mode. Currently: "+this._tree.settings.rules.draggable);this._isEditMode=enable;this.saveTreeState(this._app);var app=this._app;this._app="temp";this.rebuildTree(app);this._debug("Edit mode. New Mode: "+this._tree.settings.rules.draggable);this._appActions.showSpeachBubble("info","Tree Edit Mode","The tree is now operating in edit mode");},rebuildTree:function(app){this._debug("rebuildTree");if(this._app==null||(this._app.toLowerCase()==app.toLowerCase())){this._debug("not rebuilding");return;}
else{this._app=app;}
$("div").remove(".tree-default-context");this._tree.destroy();this._container.hide();var _this=this;var saveData=this._container.data("tree_"+app);if(saveData!=null){this._debug("rebuildTree: rebuilding from cache: app = "+app);this._initNode=saveData.d;this._tree=$.tree_create();this._tree.init(this._container,this._getInitOptions());this._tree.rename=this._umbracoRename;this._configureNodes(this._container.find("li"),true);var lastSelected=saveData.selected!=null?$(saveData.selected[0]).attr("id"):null;if(lastSelected!=null){var _this=this;var foundHandler=function(EV,node){_this.removeEventHandler("syncFound",foundHandler);this._debug("rebuildTree: node synced, selecting node...");_this.selectNode(node,false,true);this._container.show();};this._debug("rebuildTree: syncing to last selected: "+lastSelected);this.addEventHandler("syncFound",foundHandler);this.setActiveTreeType($(saveData.selected[0]).attr("umb:type"));this.syncTree(lastSelected);}
else{this._container.show();}
return;}
var parameters="{'app':'"+app+"','showContextMenu':'"+this._showContext+"', 'isDialog':'"+this._isDialog+"'}"
this._currentAJAXRequest=true;$.ajax({type:"POST",url:this._serviceUrl,data:parameters,contentType:"application/json; charset=utf-8",dataType:"json",success:function(msg){msg=msg.d;if($.inArray(msg.app,_this._loadedApps)==-1){_this._debug("loading js for app: "+msg.app);_this._loadedApps.push(msg.app);_this._container.after("<script>"+msg.js+"</script>");}
_this._initNode=eval(msg.json);_this._tree=$.tree_create();_this._tree.init(_this._container,_this._getInitOptions());_this._tree.rename=_this._umbracoRename;_this._container.show();_this._loadChildNodes(_this._container.find("li:first"),null);_this._currentAJAXRequest=false;$(_this).trigger("rebuiltTree",[msg.app]);},error:function(e){_this._debug("rebuildTree: AJAX error occurred");_this._currentAJAXRequest=false;$(_this).trigger("ajaxError",[{msg:"rebuildTree"}]);}});},saveTreeState:function(appAlias){this._debug("saveTreeState: "+appAlias+" : ajax request? "+this._currentAJAXRequest);if(this._currentAJAXRequest){this._container.data("tree_"+appAlias,null);return;}
var treeData=this._tree.getJSON(null,["id","umb:type","class","rel"],["umb:nodedata","href","class","style"]);this._updateJSONNodeState(treeData);this._container.data("tree_"+appAlias,{selected:this._tree.selected,d:treeData});},_updateJSONNodeState:function(obj){var node=$("li[id='"+obj.attributes.id+"']").filter(function(){return($(this).attr("umb:type")==obj.attributes["umb:type"]);});var c=node.attr("class");if(c!=null){var state=c.indexOf("open")>-1?"open":c.indexOf("closed")>-1?"closed":null;if(state!=null)obj.state=state;}
if(obj.children!=null){for(var x in obj.children){this._updateJSONNodeState(obj.children[x]);}}},syncTree:function(path,forceReload){this._debug("syncTree: "+path+", "+forceReload);this._syncTree.call(this,path,forceReload,null,null);},childNodeCreated:function(){this._debug("childNodeCreated");var childrenIds=new Array();this._actionNode.jsNode.find("ul > li").each(function(){childrenIds.push($(this).attr("id"));});var _this=this;var currId=this._actionNode.nodeId;this.reloadActionNode(true,false,function(success){if(success&&childrenIds.length>0){var found=false;var actionNode=_this.findNode(currId);if(actionNode){actionNode.find("ul > li").each(function(){if($.inArray($(this).attr("id"),childrenIds)==-1){found=$(this);}});}
if(found){_this._debug("childNodeCreated: selecting new child node: "+found.attr("id"));_this.selectNode(found,true,true);$(_this).trigger("newChildNodeFound",[found]);return;}}
_this._debug("childNodeCreated: could not select new child!");});},moveNode:function(nodeId,parentPath){this._debug("moveNode");var old=this.findNode(nodeId);if(old)old.remove();var newPath=parentPath+","+nodeId;var _this=this;var foundHandler=function(EV,node){_this.removeEventHandler("syncFound",foundHandler);_this.selectNode(node,false,true);$(_this).trigger("nodeMoved",[node]);};this.addEventHandler("syncFound",foundHandler);this.syncTree(newPath);},copyNode:function(nodeId,parentPath){this._debug("copyNode");var originalNode=this.findNode(nodeId);var _this=this;var foundHandler=function(EV,node){_this.removeEventHandler("syncFound",foundHandler);_this._loadChildNodes(node,null);if(originalNode)_this.selectNode(originalNode,true);$(_this).trigger("nodeCopied",[node]);};this.addEventHandler("syncFound",foundHandler);this.syncTree(parentPath);},findNode:function(nodeId,findGlobal){var _this=this;var branch=this._container.find("li[id='"+nodeId+"']");if(!findGlobal)branch=branch.filter(function(){return($(this).attr("umb:type")==_this._activeTreeType);});var found=branch.length>0?branch:false;this._debug("findNode: "+nodeId+" in '"+this._activeTreeType+"' tree. Found? "+found.length);return found;},selectNode:function(node,supressEvent,reselect){this._debug("selectNode, edit mode? "+this._isEditMode);var selectedId=this._tree.selected!=null?$(this._tree.selected[0]).attr("id"):null;if(reselect||(selectedId==null||selectedId!=node.attr("id"))){if(supressEvent||this._isEditMode){this._tree.settings.callback.onselect=function(){};}
this._tree.select_branch(node);var _this=this;this._tree.settings.callback.onselect=function(N,T){_this.onSelect(N,T)};}},reloadActionNode:function(supressSelect,supressChildReload,callback){this._debug("reloadActionNode: supressSelect = "+supressSelect+", supressChildReload = "+supressChildReload);if(this._actionNode!=null&&this._actionNode.jsNode!=null){var nodeParent=this._actionNode.jsNode.parents("li:first");this._debug("reloadActionNode: found "+nodeParent.length+" parent nodes");if(nodeParent.length==1){var nodeDef=this._getNodeDef(nodeParent);this._debug("reloadActionNode: loading ajax for node: "+nodeDef.nodeId);var _this=this;var toReplace=$("<li class='last'><a class='loading' href='#'><div>"+(this._tree.settings.lang.loading||"Loading ...")+"</div></a></li>").replaceAll(this._actionNode.jsNode);$.get(this._getUrl(nodeDef.sourceUrl),null,function(msg){if(!msg||msg.length==0){_this._debug("reloadActionNode: error loading ajax data, performing jsTree refresh");_this._tree.refresh();if(callback!=null)callback.call(_this,false);return;}
var oFound=null;for(var o in msg){if(msg[o].attributes!=null&&msg[o].attributes.id==_this._actionNode.nodeId){oFound=_this._tree.parseJSON(msg[o]);if($(oFound).attr("umb:type")==_this._actionNode.treeType){break;}
else{oFound=null;}}}
if(oFound!=null){_this._debug("reloadActionNode: node is refreshed!");var reloaded=$(oFound).replaceAll(toReplace);_this._configureNodes(reloaded,true);if(!supressSelect)_this.selectNode(reloaded);if(!supressChildReload){_this._loadChildNodes(reloaded,function(){if(callback!=null)callback.call(_this,true);});}
else{if(callback!=null)callback.call(_this,true);}}
else{_this._debug("reloadActionNode: error finding child node in ajax data, performing jsTree refresh");_this._tree.refresh();if(callback!=null)callback.call(_this,false);}},"json");return;}
this._debug("reloadActionNode: error finding parent node, performing jsTree refresh");this._tree.refresh();if(callback!=null)callback.call(this,false);}},getActionNode:function(){return this._actionNode;},setActiveTreeType:function(treeType){this._activeTreeType=treeType;},onNodeDeleting:function(EV){this._debug("onNodeDeleting")
this._tree.close_branch(this._actionNode.jsNode);this._actionNode.jsNode.find("a").attr("class","loading");this._actionNode.jsNode.find("a").css("background-image","");this._actionNode.jsNode.find("a").html(this._uiKeys['deleting']);},onNodeDeleted:function(EV){this._debug("onNodeDeleted");this._actionNode.jsNode.find("a").removeClass("loading");this._tree.close_branch(this._actionNode.jsNode);this._actionNode.jsNode.hide("drop",{direction:"down"},400);this._updateRecycleBin();},onNodeRefresh:function(EV){this._debug("onNodeRefresh");this._loadChildNodes(this._actionNode.jsNode,null);},onSelect:function(NODE,TREE_OBJ){this._debug("onSelect, edit mode? "+this._isEditMode);if(this._isEditMode){this._tree.rename(NODE);return false;}
else{this.setActiveTreeType($(NODE).attr("umb:type"));var js=$(NODE).children("a").attr("href").replace("javascript:","");this._debug("onSelect: js: "+js);try{var func=eval(js);if(func!=null){func.call();}}catch(e){}
return true;}},onOpen:function(NODE,TREE_OBJ){this._debug("onOpen: "+$(NODE).attr("id"));var nodes=$(NODE).find("ul > li");this._configureNodes(nodes);return true;},onBeforeOpen:function(NODE,TREE_OBJ){var nodeDef=this._getNodeDef($(NODE));this._debug("onBeforeOpen: "+nodeDef.nodeId);this._currentAJAXRequest=true;TREE_OBJ.settings.data.url=this._getUrl(nodeDef.sourceUrl);},onJSONData:function(DATA,TREE_OBJ){this._debug("onJSONData");this._currentAJAXRequest=false;return DATA;},onChange:function(NODE,TREE_OBJ){if(this._treeType=="checkbox"){var $this=$(NODE).is("li")?$(NODE):$(NODE).parent();if($this.children("a").hasClass("checked"))$this.children("a").removeClass("checked")
else $this.children("a").addClass("checked");}
else if(this._treeType=="inheritedcheckbox"){var $this=$(NODE).is("li")?$(NODE):$(NODE).parent();if($this.children("a.unchecked").size()==0){TREE_OBJ.container.find("a").addClass("unchecked");}
$this.children("a").removeClass("clicked");if($this.children("a").hasClass("checked")){$this.find("li").andSelf().children("a").removeClass("checked").removeClass("undetermined").addClass("unchecked");var state=0;}
else{$this.find("li").andSelf().children("a").removeClass("unchecked").removeClass("undetermined").addClass("checked");var state=1;}
$this.parents("li").each(function(){if(state==1){if($(this).find("a.unchecked, a.undetermined").size()-1>0){$(this).parents("li").andSelf().children("a").removeClass("unchecked").removeClass("checked").addClass("undetermined");return false;}
else $(this).children("a").removeClass("unchecked").removeClass("undetermined").addClass("checked");}
else{if($(this).find("a.checked, a.undetermined").size()-1>0){$(this).parents("li").andSelf().children("a").removeClass("unchecked").removeClass("checked").addClass("undetermined");return false;}
else $(this).children("a").removeClass("checked").removeClass("undetermined").addClass("unchecked");}});}
$(this).trigger("nodeClicked",[NODE]);},onRightClick:function(NODE,TREE_OBJ,EV){this._actionNode=this._getNodeDef($(NODE));this.setActiveTreeType($(NODE).attr("umb:type"));this._debug("onRightClick: menu = "+this._actionNode.menu);$("div").remove(".tree-default-context");if(this._actionNode.menu!=""){TREE_OBJ.settings.ui.context=this._getContextMenu(this._actionNode.menu);TREE_OBJ.context_menu();var timeout=null;TREE_OBJ.context.mouseenter(function(){clearTimeout(timeout);});TREE_OBJ.context.mouseleave(function(){timeout=setTimeout(function(){TREE_OBJ.hide_context();},400);});this._checkContextMenu(TREE_OBJ);}},onBeforeMove:function(NODE,REF_NODE,TYPE,TREE_OBJ){var nodeDef=this._getNodeDef($(NODE));var nodeParent=nodeDef.jsNode.parents("li:first");var nodeParentDef=this._getNodeDef(nodeParent);var refNodeDef=this._getNodeDef($(REF_NODE));this._debug("onBeforeMove, TYPE: "+TYPE);this._debug("onBeforeMove, NODE ID: "+nodeDef.nodeId);this._debug("onBeforeMove, PARENT NODE ID: "+nodeParentDef.nodeId);this._debug("onBeforeMove, REF NODE ID: "+refNodeDef.nodeId);switch(TYPE){case"inside":if(nodeParentDef.nodeId==refNodeDef.nodeId){this._appActions.showSpeachBubble("warning","Tree Edit Mode","Cannot move a node to it's same parent node");return false;}
break;case"before":break;case"after":break;}
return false;},_checkContextMenu:function(TREE_OBJ,count){if(count>20)
return;var isVisible=TREE_OBJ.context.is(":visible");if(!isVisible){this._debug("_checkContextMenu - waiting for visible menu");var _this=this;setTimeout(function(){_this._checkContextMenu(TREE_OBJ,++count);},50);return;}
var offset=TREE_OBJ.context.offset();var bodyHeight=$("body").innerHeight();var ctxHeight=TREE_OBJ.context.height();this._debug("_checkContextMenu - offset top: "+offset.top+", bodyHeight: "+bodyHeight+", ctxHeight: "+ctxHeight);var diff=(offset.top+ctxHeight)-bodyHeight;if(diff>0){this._debug("_checkContextMenu - Menu needs adjusting, new top: "+diff);TREE_OBJ.context.css("top",(offset.top-diff-10)+"px");}},_debug:function(strMsg){if(this._isDebug){Sys.Debug.trace("UmbracoTree: "+strMsg);}},_configureNodes:function(nodes,reconfigure){var _this=this;if(!reconfigure){nodes=nodes.not("li[class*='loaded']");}
this._debug("_configureNodes: "+nodes.length);var rxInput=new RegExp("\\boverlay-\\w+\\b","gi");nodes.each(function(){if(_this._treeType!="standard"){$(this).children("a:first").css("background","");return;}
$(this).children("div").remove();var m=$(this).attr("class").match(rxInput);if(m!=null){for(i=0;i<m.length;i++){_this._debug("_configureNodes: adding overlay: "+m[i]+" for node: "+$(this).attr("id"));$(this).children("a:first").before("<div class='overlay "+m[i]+"'></div>");}}
var txt=$(this).children("a").html();$(this).children("a").html("<div>"+txt+"</div>");$(this).addClass("loaded");});},_getNodeDef:function(NODE){var nodedata=$(NODE).children("a").metadata({type:'attr',name:'umb:nodedata'});this._debug("_getNodeDef: "+$(NODE).attr("id")+", "+nodedata.nodeType+", "+nodedata.source);var def=new Umbraco.Controls.NodeDefinition();def.updateDefinition(this._tree,$(NODE),$(NODE).attr("id"),$(NODE).find("a > div").html(),nodedata.nodeType,nodedata.source,nodedata.menu,$(NODE).attr("umb:type"));return def;},_updateRecycleBin:function(){this._debug("_updateRecycleBin BinId: "+this._recycleBinId);var rNode=this.findNode(this._recycleBinId,true);if(rNode){this._actionNode=this._getNodeDef(rNode);var _this=this;this.reloadActionNode(true,true,function(success){if(success){_this.findNode(_this._recycleBinId,true).effect("highlight",{},1000);}});}},_loadChildNodes:function(liNode,callback){this._debug("_loadChildNodes: "+liNode);liNode.removeClass("leaf");this._tree.close_branch(liNode,true);liNode.children("ul:eq(0)").html("");this._tree.open_branch(liNode,false,callback);},_syncTree:function(path,forceReload,numPaths,numAsync){this._debug("_syncTree");var paths=path.split(",");var found=null;var foundIndex=null;if(numPaths==null)numPaths=(paths.length-0);for(var i=0;i<numPaths;i++){foundIndex=paths.length-(1+i);found=this.findNode(paths[foundIndex]);this._debug("_syncTree: finding... "+paths[foundIndex]+" found? "+found);if(found)break;}
if(!found){this._debug("no node found in path: "+path+" : "+numPaths);$(this).trigger("syncNotFound",[path]);return;}
if(found.attr("id")!=paths[paths.length-1]){var _this=this;this._loadChildNodes(found,function(NODE,TREE_OBJ){var pathsToSearch=paths.length-(Number(foundIndex)+1);if(_this.findNode(paths[foundIndex+1])){_this._syncTree(path,forceReload,pathsToSearch,(numAsync==null?numAsync==1:++numAsync));}
else{_this._debug("node not found in children: "+path+" : "+numPaths);$(this).trigger("syncNotFound",[path]);}});}
else{var doReload=(forceReload&&(numAsync==null||numAsync<1));this._debug("_syncTree: found! numAsync: "+numAsync+", forceReload: "+forceReload);if(doReload){this._actionNode=this._getNodeDef(found);this.reloadActionNode(true,true,null);}
else{if(found.attr("id")!="-1")this.selectNode(found,true);this._configureNodes(found,doReload);}
$(this).trigger("syncFound",[found]);}},_getContextMenu:function(strMenu){this._debug("_getContextMenu: "+strMenu);var newMenu=new Array();for(var i=0;i<strMenu.length;i++){var letter=strMenu.charAt(i);var menuItem=this._getMenuItemByLetter(letter);if(menuItem!=null)newMenu.push(menuItem);}
return newMenu;},_getMenuItemByLetter:function(letter){if(letter==",")return"separator";for(var m in this._fullMenu){if(this._fullMenu[m].id==letter){return this._fullMenu[m];}}
return null;},_init:function(jFullMenu,jInitNode,treeContainer,appActions,uiKeys,app,showContext,isDialog,treeType,serviceUrl,dataUrl,umbClientFolder,recycleBinId){this._debug("_init: creating new tree with class/id: "+treeContainer.attr("class")+" / "+treeContainer.attr("id"));this._fullMenu=jFullMenu;this._initNode=jInitNode;this._appActions=appActions;this._uiKeys=uiKeys;this._app=app;this._showContext=showContext;this._isDialog=isDialog;this._treeType=treeType;this._serviceUrl=serviceUrl;this._dataUrl=dataUrl;this._umb_clientFolderRoot=umbClientFolder;this._recycleBinId=recycleBinId;if(this._appActions!=null){var _this=this;this._appActions.addEventHandler("nodeDeleting",function(E){_this.onNodeDeleting(E)});this._appActions.addEventHandler("nodeDeleted",function(E){_this.onNodeDeleted(E)});this._appActions.addEventHandler("nodeRefresh",function(E){_this.onNodeRefresh(E)});}
this._container=treeContainer;this._tree=$.tree_create();this._tree.init(this._container,this._getInitOptions());this._tree.rename=this._umbracoRename;if($.inArray(app,this._loadedApps)==-1){this._loadedApps.push(app);}
this._loadChildNodes(this._container.find("li:first"),null);},_umbracoRename:function(obj){if(this.locked)return this.error("LOCKED");obj=obj?this.get_node(obj):this.selected;var _this=this;if(!obj||!obj.size())return this.error("RENAME: NO NODE SELECTED");if(!this.check("renameable",obj))return this.error("RENAME: NODE NOT RENAMABLE");if(!this.settings.callback.beforerename.call(null,obj.get(0),_this.current_lang,_this))return this.error("RENAME: STOPPED BY USER");obj.parents("li.closed").each(function(){_this.open_branch(this)});obj=obj.find("a:first div");last_value=obj.html();_this.inp=$("<input type='text' autocomplete='off' />");_this.inp.val(last_value.replace(/&/g,"&").replace(/>/g,">").replace(/</g,"<")).bind("mousedown",function(event){event.stopPropagation();}).bind("mouseup",function(event){event.stopPropagation();}).bind("click",function(event){event.stopPropagation();}).bind("keyup",function(event){var key=event.keyCode||event.which;if(key==27){this.value=last_value;this.blur();return}
if(key==13){this.blur();return}});var rb={};rb[this.container.attr("id")]=this.get_rollback();var spn=$("<div />").addClass($(obj).parent().attr("class")).addClass("renaming").append(_this.inp);spn.attr("style",$(obj).attr("style"));obj.parent().hide();obj.parents("li:first").prepend(spn);},_getUrl:function(nodeSource){if(nodeSource==null||nodeSource==""){return this._dataUrl;}
var params=nodeSource.split("?")[1];return this._dataUrl+"?"+params+"&rnd2="+Umbraco.Utils.generateRandom();},_getInitOptions:function(){this._debug("_getInitOptions");var _this=this;var options={data:{type:"json",async:true,url:"",json:this._initNode,async_data:function(NODE){return null;}},ui:{dots:false,rtl:false,animation:false,hover_mode:true,theme_path:this._umb_clientFolderRoot+"/Tree/Themes/",theme_name:"umbraco",context:null},lang:{new_node:"New folder",loading:"<div>"+(this._tree.settings.lang.loading||"Loading ...")+"</div>"},rules:{metadata:"umb:nodedata",creatable:"none",draggable:(!this._isEditMode?"none":["dataNode"]),},callback:{onrgtclk:function(N,T,E){_this.onRightClick(N,T,E)},beforemove:function(N,RN,TYPE,T){_this.onBeforeMove(N,RN,TYPE,T)},beforeopen:function(N,T){_this.onBeforeOpen(N,T)},onopen:function(N,T){_this.onOpen(N,T)},onselect:function(N,T){_this.onSelect(N,T)},onchange:function(N,T){_this.onChange(N,T)},onJSONdata:function(D,T){return _this.onJSONData(D,T)}}};return options;}};}})(jQuery);