function workInProgress(isWorking) { var loader = $(".loader"); var submitButton = $(".submitter"); if (isWorking) { loader.removeClass("unseen"); submitButton.attr("disabled", "disabled"); } else { loader.addClass("unseen"); submitButton.removeAttr("disabled"); } } function log(arguments) { if (window.console && console && console.log) { if ($.isArray(arguments)) { if ((Array.prototype.slice.call(arguments)).length == 1 && typeof Array.prototype.slice.call(arguments)[0] == 'string') { var txt = (Array.prototype.slice.call(arguments)).toString(); console.log(txt); return txt; } else { var txt = Array.prototype.slice.call(arguments); console.log(txt); return txt; } } else { console.log(arguments); return arguments; } } } $(document).ready(function () { var tree = $('#container').dynatree({ onActivate: function (node) { if (node && node.data.title !== "Experiment") { $('input[name="RemoveNode"]').removeAttr("disabled"); } else if (node) { $('input[name="RemoveNode"]').attr("disabled", "disabled"); } }, onDeactivate: function (node) { }, dnd: { autoExpandMS: 750, onDragStart: function (node) { return node.data.title !== "Experiment"; }, onDragEnter: function (node, sourceNode) { return true; }, onDragOver: function (node, sourceNode, hitMode) { return node.data.title !== "Experiment" || hitMode === "over"; }, onDrop: function (node, sourceNode, hitMode, ui, draggable) { if (sourceNode) { sourceNode.move(node, hitMode); } else { newNode = { title: draggable.element[0].id }; if (hitMode == "over") { node.addChild(newNode); node.expand(true); } else if (hitMode == "before") { node.parent.addChild(newNode, node); } else { node.parent.addChild(newNode, node.getNextSibling()); } } }, onDragLeave: function (node, sourceNode) { } } }); $('.dragables').each(function () { $(this).draggable({ revert: true, connectToDynatree: true, cursorAt: { top: -5, left: -5 }, helper: "clone" }); }); $(".submitter").each(function () { var btn = $(this); $(this).click(function () { workInProgress(true); var name = $('input[name="Name"]').val(); var root = { Experiment: $("#container").dynatree("getTree").toDict(), Name: name }; $.ajax({ type: "POST", url: '/Experiment/Save', contentType: "application/json; charset=utf-8", dataType: "json", data: JSON.stringify(root), success: function (result) { log(result); if (result.success) { var clearers = $("#experiments .clearer"); if (clearers && clearers.length > 0) { var experimentDiv = $('
' + name + '
' + name + '