Skip to content

Commit 26fd2ef

Browse files
committed
close softwareloop#40 cmis entry update
1 parent cc6b21c commit 26fd2ef

File tree

4 files changed

+161
-31
lines changed

4 files changed

+161
-31
lines changed

src/main/amp/web/js/softwareloop/inboxes/Inbox.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ define([
119119
},
120120

121121
postItems: function () {
122-
console.log("Item class", this.itemClass);
123122
require([this.itemClass], lang.hitch(this, function (itemClass) {
124123
try {
125124
var i;

src/main/amp/web/js/softwareloop/inboxes/Item.js

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ define([
3030
entry: null,
3131
entryId: null,
3232
entryAttributes: null,
33-
entryAttributeArrays: null,
3433

3534
previewUrl: "",
3635
downloadUrl: "",
@@ -52,7 +51,6 @@ define([
5251
bindToEntry: function () {
5352
this.entryId = this.entry.getElementsByTagName("id")[0].firstChild.nodeValue.substring(9);
5453
this.entryAttributes = {};
55-
this.entryAttributeArrays = {};
5654
this.parseProperties("propertyId",
5755
function (stringValue) {
5856
return stringValue;
@@ -79,10 +77,17 @@ define([
7977
for (var i = 0; i < propertyStrings.length; i++) {
8078
var propertyString = propertyStrings[i];
8179
var cmisAttributeName =
82-
propertyString.getAttribute("propertyDefinitionId").replace(":", "_");
80+
propertyString.getAttribute("propertyDefinitionId");
81+
var entryAttribute = {
82+
tagName: tagName,
83+
values: [],
84+
value: function () {
85+
return (this.values.length > 0) ? this.values[0] : null
86+
}
87+
};
88+
this.entryAttributes[cmisAttributeName] = entryAttribute;
8389
var valueNode = browser.getElementsByTagName(propertyString, "cmis", "value");
8490
if (valueNode) {
85-
var cmisAttributeValues = [];
8691
array.forEach(valueNode, function (current) {
8792
var cmisAttributeValue = null;
8893
try {
@@ -91,22 +96,14 @@ define([
9196
} catch (e) {
9297
cmisAttributeValue = null;
9398
}
94-
cmisAttributeValues.push(cmisAttributeValue);
99+
entryAttribute.values.push(cmisAttributeValue);
95100
});
96-
this.entryAttributeArrays[cmisAttributeName] = cmisAttributeValues;
97-
if (cmisAttributeValues.length > 0) {
98-
this.entryAttributes[cmisAttributeName] = cmisAttributeValues[0];
99-
} else {
100-
this.entryAttributes[cmisAttributeName] = null;
101-
}
102-
} else {
103-
this.entryAttributes[cmisAttributeName] = null;
104101
}
105102
}
106103
},
107104

108105
composeLines: function () {
109-
if (this.entryAttributes.cmis_baseTypeId === "cmis:document") {
106+
if (this.entryAttributes["cmis:baseTypeId"].value() === "cmis:document") {
110107
this.previewUrl = lang.replace(
111108
"{proxyUri}api/node/workspace/SpacesStore/{entryId}/content/thumbnails/doclib?c=queue&ph=true&lastModified=1",
112109
{
@@ -127,36 +124,36 @@ define([
127124
{
128125
proxyUri: Alfresco.constants.PROXY_URI,
129126
entryId: this.entryId,
130-
filename: encodeURIComponent(this.entryAttributes.cmis_name)
127+
filename: encodeURIComponent(this.entryAttributes["cmis:name"].value())
131128
}
132129
);
133-
this.escapedLine1 = this.encodeHTML(this.entryAttributes.cmis_name);
130+
this.escapedLine1 = this.encodeHTML(this.entryAttributes["cmis:name"].value());
134131
if (!this.escapedLine1) {
135132
this.escapedLine1 = "";
136133
}
137-
this.escapedLine2 = this.encodeHTML(this.entryAttributes.cm_title);
134+
this.escapedLine2 = this.encodeHTML(this.entryAttributes["cm:title"].value());
138135
if (!this.escapedLine2) {
139136
this.escapedLine2 = "";
140137
}
141138
var line3 = this.message(
142139
"modified.on.by",
143140
{
144-
date: locale.format(this.entryAttributes.cmis_lastModificationDate, {
141+
date: locale.format(this.entryAttributes["cmis:lastModificationDate"].value(), {
145142
formatLength: "medium",
146143
locale: Alfresco.constants.JS_LOCALE.substring(0, 2)
147144
}),
148-
user: this.entryAttributes.cmis_lastModifiedBy
145+
user: this.entryAttributes["cmis:lastModifiedBy"].value()
149146
}
150147
);
151148
this.escapedLine3 = this.encodeHTML(line3);
152149
if (!this.escapedLine3) {
153150
this.escapedLine3 = "";
154151
}
155-
this.escapedLine4 = this.encodeHTML(this.entryAttributes.cm_description);
152+
this.escapedLine4 = this.encodeHTML(this.entryAttributes["cm:description"].value());
156153
if (!this.escapedLine4) {
157154
this.escapedLine4 = "";
158155
}
159-
var versionLabel = this.entryAttributes.cmis_versionLabel;
156+
var versionLabel = this.entryAttributes["cmis:versionLabel"].value();
160157
if ("0.0" === versionLabel) {
161158
versionLabel = "1.0";
162159
}
@@ -168,7 +165,7 @@ define([
168165
this.downloadLabel = this.message(
169166
"download.size",
170167
{
171-
size: this.getHumanSize(this.entryAttributes.cmis_contentStreamLength)
168+
size: this.getHumanSize(this.entryAttributes["cmis:contentStreamLength"].value())
172169
}
173170
);
174171
},
@@ -188,7 +185,8 @@ define([
188185
"Document approved",
189186
"This is just a stub action. " +
190187
"To provide a real implementation you should customize " +
191-
"Item.approveAction()"
188+
"Item.approveAction()",
189+
true
192190
);
193191
},
194192

@@ -197,19 +195,22 @@ define([
197195
"Document rejected",
198196
"This is just a stub action. " +
199197
"To provide a real implementation you should customize " +
200-
"Item.rejectAction()"
198+
"Item.rejectAction()",
199+
true
201200
);
202201
},
203202

204-
showDialog: function (title, content) {
203+
showDialog: function (title, content, reloadOnHide) {
205204
var myDialog = new AlfDialog({
206205
title: title,
207206
content: content,
208207
style: "width: 300px"
209208
});
210-
myDialog.on("hide", function () {
211-
location.reload(false);
212-
});
209+
if (reloadOnHide) {
210+
myDialog.on("hide", function () {
211+
location.reload(false);
212+
});
213+
}
213214
myDialog.show();
214215
},
215216

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* @author Paolo Predonzani (http://softwareloop.com/)
3+
*/
4+
5+
define([
6+
"dojo/_base/declare",
7+
"dojo/_base/lang",
8+
"dojox/html/entities"
9+
], function (declare, lang, entities) {
10+
11+
var encodeMap = [
12+
["&", "amp"],
13+
["<", "lt"],
14+
[">", "gt"],
15+
["'", "apos"],
16+
['"', "quot"]
17+
];
18+
19+
var xmlDeclarationTemplate = "<?xml version='{version}' encoding='{encoding}'?>"
20+
21+
return declare(null, {
22+
constructor: function () {
23+
this.text = "";
24+
this.open = false;
25+
},
26+
27+
escape: function (text) {
28+
return entities.encode(text, encodeMap);
29+
},
30+
31+
writeXmlDeclaration: function (version, encoding) {
32+
this.text += lang.replace(xmlDeclarationTemplate, {
33+
version: version,
34+
encoding: encoding
35+
});
36+
},
37+
38+
closeIfNeeded: function () {
39+
if (this.open) {
40+
this.text += ">";
41+
this.open = false;
42+
}
43+
},
44+
45+
openElement: function (name) {
46+
this.closeIfNeeded();
47+
this.text += "<" + this.escape(name);
48+
this.open = true;
49+
},
50+
51+
closeElement: function (name) {
52+
this.closeIfNeeded();
53+
this.text += "</" + this.escape(name) + ">";
54+
},
55+
56+
addAttribute: function (name, value) {
57+
this.text += " " + name + '="' + this.escape(value) + '"'
58+
},
59+
60+
write: function (text) {
61+
this.closeIfNeeded();
62+
this.text += this.escape(text);
63+
},
64+
65+
toString: function () {
66+
this.closeIfNeeded();
67+
return this.text;
68+
}
69+
});
70+
});

src/main/amp/web/js/softwareloop/util/cmis.js

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
define([
2-
"dojo/date/locale"
3-
], function (locale) {
2+
"dojo/_base/array",
3+
"dojo/date/locale",
4+
"dojo/request/xhr",
5+
"softwareloop/util/XmlBuffer"
6+
], function (array, locale, xhr, XmlBuffer) {
47
var datePattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
58

69
var formatOptions = {
@@ -17,6 +20,63 @@ define([
1720

1821
parseDate: function (stringValue) {
1922
return locale.parse(stringValue, formatOptions);
23+
},
24+
25+
updateEntry: function (url, entryAttributes, successCallback, failureCallback) {
26+
var now = new Date();
27+
var xb = new XmlBuffer();
28+
xb.writeXmlDeclaration("1.0", "UTF-8");
29+
xb.openElement("atom:entry");
30+
xb.addAttribute("xmlns:atom", "http://www.w3.org/2005/Atom");
31+
xb.addAttribute("xmlns:cmis", "http://docs.oasis-open.org/ns/cmis/core/200908/");
32+
xb.addAttribute("xmlns:cmisra", "http://docs.oasis-open.org/ns/cmis/restatom/200908/");
33+
34+
xb.openElement("atom:id");
35+
xb.write("urn:uuid:00000000-0000-0000-0000-00000000000");
36+
xb.closeElement("atom:id");
37+
38+
xb.openElement("atom:title");
39+
xb.closeElement("atom:title");
40+
41+
xb.openElement("atom:updated");
42+
xb.write(now.toISOString());
43+
xb.closeElement("atom:updated");
44+
45+
xb.openElement("cmisra:object");
46+
xb.openElement("cmis:properties");
47+
48+
for (var cmisAttributeName in entryAttributes) {
49+
if (entryAttributes.hasOwnProperty(cmisAttributeName)) {
50+
var entryAttribute = entryAttributes[cmisAttributeName];
51+
console.log(entryAttribute);
52+
var elementName = "cmis:" + entryAttribute.tagName;
53+
xb.openElement(elementName);
54+
xb.addAttribute("propertyDefinitionId", cmisAttributeName);
55+
array.forEach(entryAttribute.values, function (value) {
56+
xb.openElement("cmis:value");
57+
xb.write(value.toString());
58+
xb.closeElement("cmis:value");
59+
});
60+
xb.closeElement(elementName);
61+
}
62+
}
63+
64+
xb.closeElement("cmis:properties");
65+
xb.closeElement("cmisra:object");
66+
67+
xb.closeElement("atom:entry");
68+
69+
xhr(url, {
70+
method: "PUT",
71+
headers: {
72+
"Content-Type": "application/atom+xml;type=entry",
73+
"Alfresco-CSRFToken": Alfresco.util.CSRFPolicy.getToken()
74+
},
75+
data: xb.toString()
76+
}).then(
77+
successCallback,
78+
failureCallback
79+
);
2080
}
2181
}
2282
});

0 commit comments

Comments
 (0)