Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions plugins/browsing/browsing.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<label for="resourceName">Resource:</label>
</span>
<span>
<input class="labelBox" id="resourceName" name="resourceName" value="" data-dojo-type="dijit.form.TextBox"/>
<input readonly="readonly" class="labelBox" id="resourceName" name="resourceName" value="" data-dojo-type="dijit.form.TextBox"/>
</span>
</div>
<div>
Expand All @@ -81,15 +81,15 @@
<label for="created">Created:</label>
</span>
<span>
<input class="labelBox" type="text" id="created" name="created" value="" data-dojo-type="dijit.form.TextBox"/>
<input readonly="readonly" class="labelBox" type="text" id="created" name="created" value="" data-dojo-type="dijit.form.TextBox"/>
</span>
</div>
<div>
<span>
<label for="lastModified">Last Modified:</label>
</span>
<span>
<input class="labelBox" type="text" id="lastModified" name="lastModified" value="" data-dojo-type="dijit.form.TextBox"/>
<input readonly="readonly" class="labelBox" type="text" id="lastModified" name="lastModified" value="" data-dojo-type="dijit.form.TextBox"/>
</span>
</div>
</fieldset>
Expand All @@ -98,17 +98,13 @@
<span>
<label for="owner">Owner:</label>
</span>
<span>
<input id="owner" name="owner" value="" data-dojo-type="dijit.form.TextBox"/>
</span>
<span id="ownerSelect"/>
</div>
<div>
<span>
<label for="group">Group:</label>
</span>
<span>
<input id="group" name="group" value="" data-dojo-type="dijit.form.TextBox"/>
</span>
<span id="groupSelect"/>
</div>
<div>
<div>
Expand Down
71 changes: 65 additions & 6 deletions plugins/browsing/browsing.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ define([
var $this = this;

this.loadCSS("plugins/browsing/browsing.css");

// json data store
var restStore = new dojo.store.JsonRest({ target: "plugins/browsing/contents/" });
this.store = new dojo.data.ObjectStore({ objectStore: restStore });
Expand Down Expand Up @@ -151,6 +151,40 @@ define([
});

query("#saveProperties").on("click", function(ev) {
var changes = false;

if (registry.byId("owner").getValue() !== $this.originalOwner) {
changes = true;
}
// has the group changed?

if (registry.byId("group").getValue() !== $this.originalGroup) {
changes = true;
}
if (registry.byId("internetMediaType").getValue() !== $this.originalMime) {
changes = true;
}

if (changes) {
var params = {
resource: $this.itemId,
owner: registry.byId("owner").getValue(),
group : registry.byId("group").getValue(),
mime: registry.byId("internetMediaType").getValue()};
dojo.xhrPost({
url: "plugins/browsing/properties/",
content: params,
handleAs: "json",
load: function(data) {
$this.refresh();
$this.actionEnd();
},
error: function() {
$this.actionEnd();
util.message("Server Error", "An error occurred while communicating with the server!");
}
});
}

//do we need to save basic permissions?
if($this.permissionsStore.isDirty()) {
Expand All @@ -165,7 +199,7 @@ define([
$this.aclStore.save({
onComplete: function() {
$this.grid._refresh(); //update the main grid
changePage("browsingPage");
changePage("browsingPage");
}
});
} else {
Expand Down Expand Up @@ -195,6 +229,7 @@ define([
});

query("#closeProperties").on("click", function(ev) {

changePage("browsingPage");
});

Expand Down Expand Up @@ -292,6 +327,16 @@ define([
{name: ' ', field: 'special', width: '15%', type: dojox.grid.cells.Bool, editable: true }
]];

this.ownerSelect = new dijit.form.Select({
name: "owner",
id: "owner"
},"ownerSelect");

this.groupSelect = new dijit.form.Select({
name:"group",
id: "group"
},"groupSelect");

this.permissionsGrid = new dojox.grid.DataGrid(
{
id: 'permissions-grid',
Expand Down Expand Up @@ -400,7 +445,7 @@ define([
},*/

applyProperties: function(dlg, resources) {
console.debug("applyProperties");
console.log("applyProperties");
var $this = this;
var form = dom.byId("browsing-dialog-form");
var params = forms.toObject(form);
Expand Down Expand Up @@ -474,7 +519,7 @@ define([
);
},

delete: function(ev) {
"delete": function(ev) {
ev.preventDefault();
var $this = this;
var resources = $this.getSelected();
Expand Down Expand Up @@ -630,8 +675,22 @@ define([
registry.byId("internetMediaType").set("value", item.internetMediaType);
registry.byId("created").set("value", item.created);
registry.byId("lastModified").set("value", item.lastModified);
registry.byId("owner").set("value", item.owner);
registry.byId("group").set("value", item.group);
$this.itemId = item.id;
$this.originalOwner = item.owner;
$this.originalGroup = item.group;
$this.originalMime = item.internetMediaType;

//load the users
var restUsers = new dojo.store.JsonRest({ target: "plugins/browsing/users/" });
var usersStore = new dojo.data.ObjectStore({ objectStore: restUsers });
$this.ownerSelect.setStore(usersStore);
$this.ownerSelect.setValue(item.owner); // set current value

//load the groups
var restGroups = new dojo.store.JsonRest({ target: "plugins/browsing/groups/" });
var groupsStore = new dojo.data.ObjectStore({ objectStore: restGroups });
$this.groupSelect.setStore(groupsStore);
$this.groupSelect.setValue(item.group); // set current value

//reload the permissions store and grid
$this.permissionsStore.close();
Expand Down
2 changes: 1 addition & 1 deletion plugins/browsing/controller.xql
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ else if (ends-with($exist:resource, ".xql")) then
<set-attribute name="$exist:path" value="{$exist:path}"/>
</dispatch>

else if (starts-with($exist:path, "/contents") or starts-with($exist:path, "/properties") or starts-with($exist:path, "/permissions") or starts-with($exist:path, "/acl")) then
else if (starts-with($exist:path, "/users") or starts-with($exist:path, "/groups") or starts-with($exist:path, "/contents") or starts-with($exist:path, "/properties") or starts-with($exist:path, "/permissions") or starts-with($exist:path, "/acl")) then
let $funcs := (util:list-functions(), util:list-functions("http://exist-db.org/apps/dashboard/service"))
let $login := $login("org.exist.login", (), true())
return
Expand Down
70 changes: 63 additions & 7 deletions plugins/browsing/service.xql
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,20 @@ declare
%output:method("json")
function service:get-acl($id as xs:string, $acl-id as xs:string) as element(json:value) {
let $path := service:id-to-path($id),
$new := <json:value json:array="true">
<id></id>
<target></target>
<who></who>
<access_type></access_type>
<read></read>
<write></write>
<execute></execute>
</json:value>,
$permissions := sm:get-permissions(xs:anyURI($path))/sm:permission
return
<json:value>
<json:value>
{
for $ace in $permissions/sm:acl/sm:ace[if(string-length($acl-id) eq 0)then true() else @index eq $acl-id] return
for $ace in ($new,$permissions/sm:acl/sm:ace[if(string-length($acl-id) eq 0)then true() else @index eq $acl-id]) return
<json:value json:array="true">
<id>{$ace/string(@index)}</id>
<target>{$ace/string(@target)}</target>
Expand All @@ -318,18 +327,17 @@ declare
%rest:path("/properties/")
%rest:form-param("owner", "{$owner}")
%rest:form-param("group", "{$group}")
%rest:form-param("resources", "{$resources}")
%rest:form-param("resource", "{$resource}")
%rest:form-param("mime", "{$mime}")
%output:media-type("application/json")
%output:method("json")
function service:change-properties($resources as xs:string, $owner as xs:string?, $group as xs:string?, $mime as xs:string?) {
for $resource in $resources
function service:change-properties($resource as xs:string, $owner as xs:string, $group as xs:string, $mime as xs:string) {
let $uri := xs:anyURI($resource)
let $isCollection := xmldb:collection-available($resource)
return (
sm:chown($uri, $owner),
sm:chgrp($uri, $group),
sm:chmod($uri, service:permissions-from-form()),
xmldb:set-mime-type($resource, $mime)
if ($isCollection) then () else xmldb:set-mime-type($uri,$mime)
),
<response status="ok"/>
};
Expand Down Expand Up @@ -531,3 +539,51 @@ declare %private function service:force-json-array($nodes as node()*, $element-n
declare %private function service:path-to-col-res-path($path as xs:string) {
(replace($path, "(.*)/.*", "$1"), replace($path, ".*/", ""))
};

declare
%rest:GET
%rest:path("/groups/")
%output:media-type("application/json")
%output:method("json")
function service:groups() {
let $groups := sm:list-groups()
return (

<json:value>{

for $g in $groups

return
<json:value json:array="true">
<label>{$g}</label>
<id>{$g}</id>
<selected json:literal="true">false</selected>
</json:value>
}
</json:value>
)
};

declare
%rest:GET
%rest:path("/users/")
%output:media-type("application/json")
%output:method("json")
function service:users() {
let $users := sm:list-users()
return (

<json:value>{

for $g in $users

return
<json:value json:array="true">
<label>{$g}</label>
<id>{$g}</id>
<selected json:literal="true">false</selected>
</json:value>
}
</json:value>
)
};