Skip to content

Commit

Permalink
Added support for cut&paste in db manager.
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfgangmm committed Mar 9, 2012
1 parent eb39d36 commit 69f8692
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 11 deletions.
26 changes: 22 additions & 4 deletions modules/collections.xql
Original file line number Diff line number Diff line change
Expand Up @@ -249,19 +249,30 @@ declare function local:delete($collection as xs:string, $selection as xs:string+
$response
};

declare function local:copy($target as xs:string, $sources as xs:string+, $user as xs:string) {
declare function local:copyOrMove($operation as xs:string, $target as xs:string, $sources as xs:string+,
$user as xs:string) {
if (local:canWrite($target, $user)) then
for $source in $sources
let $isCollection := xmldb:collection-available($source)
return
try {
if ($isCollection) then
let $null := xmldb:copy($source, $target)
let $null :=
switch ($operation)
case "move" return
xmldb:move($source, $target)
default return
xmldb:copy($source, $target)
return
<response status="ok"/>
else
let $split := text:groups($source, "^(.*)/([^/]+)$")
let $null := xmldb:copy($split[2], $target, $split[3])
let $null :=
switch ($operation)
case "move" return
xmldb:move($split[2], $target, $split[3])
default return
xmldb:copy($split[2], $target, $split[3])
return
<response status="ok"/>
} catch * {
Expand All @@ -278,14 +289,21 @@ declare function local:copy($target as xs:string, $sources as xs:string+, $user
let $deleteCollection := request:get-parameter("remove", ())
let $deleteResource := request:get-parameter("remove[]", ())
let $copy := request:get-parameter("copy[]", ())
let $move := request:get-parameter("move[]", ())
let $createCollection := request:get-parameter("create", ())
let $view := request:get-parameter("view", "c")
let $collection := request:get-parameter("root", "/db")
let $collName := replace($collection, "^.*/([^/]+$)", "$1")
let $user := if (session:get-attribute('myapp.user')) then session:get-attribute('myapp.user') else "guest"
return
if (exists($copy)) then
local:copy(xmldb:encode-uri($collection), $copy, $user)
let $result := local:copyOrMove("copy", xmldb:encode-uri($collection), $copy, $user)
return
($result[@status = "fail"], $result[1])[1]
else if (exists($move)) then
let $result := local:copyOrMove("move", xmldb:encode-uri($collection), $move, $user)
return
($result[@status = "fail"], $result[1])[1]
else if (exists($deleteResource)) then
local:delete(xmldb:encode-uri($collection), $deleteResource, $user)
else if ($createCollection) then
Expand Down
Binary file added resources/images/cut.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/eXide.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ eXide.app = (function() {

manage: function() {
eXide.app.requireLogin(function() {
dbBrowser.reload(["reload", "create", "upload", "open", "copy", "paste"], "manage");
dbBrowser.reload(["reload", "create", "upload", "open", "cut", "copy", "paste"], "manage");
$("#open-dialog").dialog("option", "title", "DB Manager");
$("#open-dialog").dialog("option", "buttons", {
"Close": function() { $(this).dialog("close"); }
Expand Down
25 changes: 19 additions & 6 deletions src/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ eXide.browse.ResourceBrowser = (function () {
var $this = this;
this.container = $(container);
this.clipboard = [];
this.clipboardMode = "copy";
this.events = {
"activate": [],
"activateCollection": [],
Expand All @@ -192,9 +193,12 @@ eXide.browse.ResourceBrowser = (function () {
this.grid.setSelectionModel(selectionModel);
selectionModel.onSelectedRangesChanged.subscribe(function(e, args) {
var rows = selectionModel.getSelectedRows();
if ($this.data.length == 0) {
return;
}
var enableWrite = true;
for (var i = 0; i < rows.length; i++) {
if (!$this.data[rows[i]].writable) {
if ($this.data.length > rows[i] && !$this.data[rows[i]].writable) {
enableWrite = false;
break;
}
Expand Down Expand Up @@ -343,6 +347,11 @@ eXide.browse.ResourceBrowser = (function () {
});
},

cut: function() {
this.clipboardMode = "move";
this.copy();
},

copy: function() {
var selected = this.grid.getSelectionModel().getSelectedRows();
this.clipboard = [];
Expand All @@ -359,10 +368,9 @@ eXide.browse.ResourceBrowser = (function () {
paste: function() {
var $this = this;
$.log("Copying resources %o to %s", this.clipboard, this.collection);
$.getJSON("modules/collections.xql", {
copy: this.clipboard,
root: this.collection
},
var params = { root: this.collection };
params[this.clipboardMode] = this.clipboard;
$.getJSON("modules/collections.xql", params,
function (data) {
$.log(data.status);
if (data.status == "fail") {
Expand Down Expand Up @@ -524,7 +532,8 @@ eXide.browse.Browser = (function () {
});

button = createButton(toolbar, "Copy", "copy", 7, "page_copy.png");
button = createButton(toolbar, "Paste", "paste", 8, "page_paste.png");
button = createButton(toolbar, "Cut", "cut", 8, "cut.png");
button = createButton(toolbar, "Paste", "paste", 9, "page_paste.png");

this.selection = $(".eXide-browse-form input", container);
this.container = container;
Expand All @@ -548,6 +557,10 @@ eXide.browse.Browser = (function () {
ev.preventDefault();
$this.resources.copy();
});
$("#eXide-browse-toolbar-cut").click(function (ev) {
ev.preventDefault();
$this.resources.cut();
});
$("#eXide-browse-toolbar-paste").click(function (ev) {
ev.preventDefault();
$this.resources.paste();
Expand Down

0 comments on commit 69f8692

Please sign in to comment.