﻿(function (a) { var b = function (b, c) { function o(b, c) { var d = c.tree.getSelectedNodes(); var e = a("#" + f.selectedListTargetID); var g = e.dynatree("getRoot"); g.removeChildren(); a.each(d, function () { var a = null; var b = ""; if (typeof this.data.customType != "undefined") { a = this.data.customType; if (typeof this.data.otherText != "undefined") { b = this.data.otherText } } if (!this.parent.isSelected() || this.parent.getLevel() == 0) { g.addChild({ title: this.data.title, select: true, value: this.data.key, icon: false, unselectable: false, customType: a, otherText: b }) } }) } function n(a, b) { if (f.listType == "dualtree" || f.listType == "dualflat") { var c = d.dynatree("getRoot"); o(null, c) } if (typeof f.onPostInitCustom != "undefined") { f.onPostInitCustom(event, node) } h() } function m(b, c) { if (typeof c.data.customType != "undefined" && c.data.customType == "otherbox") { if (c.bSelected) { a(".otherbox", c.span).removeAttr("disabled") } else { a(".otherbox", c.span).attr("disabled", "disabled") } } if (f.listType == "dualtree" || f.listType == "dualflat") { o(b, c) } if (typeof f.onSelectNode != "undefined") { f.onSelectNode(b, c) } h() } function l(a, b) { if (a.data.unselectable) { a.toggleExpand() } if (typeof f.onDblClickNode != "undefined") { f.onDblClickNode(a, b) } } function k(b, c) { var d = b.getEventTargetType(c); if (typeof b.data.customType != "undefined" && b.data.customType == "otherbox") { if (!(d == null && b.bSelected) || d == "checkbox" && !b.bSelected) { if (!b.bSelected) { a(".otherbox", b.span).focus() } if (d == null && !b.bSelected) { b.select(true) } } } if (d == "title") { b.toggleSelect() } if (typeof f.onClickNode != "undefined") { f.onClickNode(b, c) } } function j(b) { if (typeof b.data.customType != "undefined" && b.data.customType == "otherbox") { b.data.otherText = a(".otherbox", b.span).val(); if (f.listType == "dualtree" || f.listType == "dualflat") { b.toggleSelect(); b.toggleSelect() } } if (typeof f.onBlurNode != "undefined") { f.onBlurNode(b) } h() } function i(a) { var b = "<span class='dynatree-title'>" + a.data.title; if (typeof a.data.customType != "undefined" && a.data.customType == "otherbox") { var c = ""; if (typeof a.data.otherText != "undefined" && a.data.otherText != null) { c = a.data.otherText } var d = ""; if (!a.bSelected) { d = "disabled='disabled'" } var e = "<input type='text' class='otherbox' value='" + c + "' " + d + " />"; b += e } b += "</span>"; return b } function h() { function i(a) { var b = { title: a.data.title, key: a.data.key }; if (typeof a.data.customType != "undefined") { b.customType = a.data.customType; if (a.data.customType == "otherbox") { if (typeof a.data.otherText != "undefined") { b.otherText = a.data.otherText } } } return b } var b = d.dynatree("getRoot").tree; var c = b.getSelectedNodes(); var e = []; a.each(c, function (a, b) { if (f.serializationMode == "selected_parent") { if (!b.parent.isSelected() || b.parent.getLevel() == 0) { e.push(i(b)) } } else { e.push(i(b)) } }); var g = JSON.stringify(e); var h = a("#" + f.valuesTargetID).get(0).tagName; if (h == "INPUT" || h == "TEXT" || h == "TEXTAREA") { a("#" + f.valuesTargetID).val(g) } else if (h == "DIV" || h == "SPAN" || h == "P" || h == "LI" || h == "LABEL") { a("#" + f.valuesTargetID).html(g) } } function g() { if (f.selectedListTargetID == null || typeof a("#" + f.selectedListTargetID).get(0) == "undefined") { throw "'listType' of 'dualtree' or 'dualflat' requires a valid jQuery object ID for 'selectedListTargetID'" } var b = a("#" + f.selectedListTargetID); b.addClass("flatTree"); if (f.listType == "dualflat") { d.addClass("flatTree") } b.dynatree({ checkbox: true, selectMode: 2, onSelect: function (a, b) { d.dynatree("getTree").selectKey(b.data.value, false) }, onCustomRender: function (a) { var b = "<span class='dynatree-title'>" + a.data.title; if (typeof a.data.customType != "undefined" && a.data.customType == "otherbox") { var c = ""; if (typeof a.data.otherText != "undefined" && a.data.otherText != null) { c = a.data.otherText } b += ": " + c } b += "</span>"; return b } }) } var d = b; var e = { single: 1, multi: 2, "multi-hier": 3 }; var f = jQuery.extend({}, a.fn.selectionList.defaults, c); if (f.valuesTargetID == null || typeof a("#" + f.valuesTargetID).get(0) == "undefined") { throw "'valuesTargetID' requires a valid ID for an object on the DOM.  You may have forgotten to set this in the options of SelectionList." } dynatreeOpts = jQuery.extend({}, { checkbox: true, idPrefix: f.idPrefix, children: f.children, selectMode: e[f.selectionMode], onCustomRender: i, onBlur: j, onClick: k, onDblClick: l, onSelect: m, onPostInit: n, keyboard: false }, f); if (f.initAjax) { dynatreeOpts.initAjax = jQuery.extend({ contentType: "application/json; charset=utf-8", dataType: "json" }, f.initAjax) } if (f.listType == "dualtree" || f.listType == "dualflat") { g() } if (f.listType == "flat") { d.addClass("flatTree") } return b.dynatree(dynatreeOpts) }; a.fn.selectionList = function (a) { return new b(this, a) }; a.fn.selectionList.defaults = { idPrefix: "tree", listType: "tree", selectionMode: "single", serializationMode: "selected"} })(jQuery)
