Skip to content

Commit

Permalink
solves #45, solves #44 Move replication to /bin/replicate using javas…
Browse files Browse the repository at this point in the history
…cript
  • Loading branch information
royteeuwen committed Nov 14, 2024
1 parent 640effe commit 96e0151
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 441 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#base=js
dictionary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
(function () {
var REPLICATE_URL = Granite.HTTP.externalize("/bin/replicate");

$(window).adaptTo("foundation-registry").register("foundation.collection.action.action", {
name: "dictionary.publish",
handler: function (name, el, config, collection, selections) {
var message = createEl("div");
var intro = createEl("p").appendTo(message);
if (selections.length === 1) {
intro.text(Granite.I18n.get("The item will be published"));
} else {
intro.text(Granite.I18n.get("{0} items will be published.", selections.length));
}
var publishPaths = getPublishPaths(selections);
var ui = $(window).adaptTo("foundation-ui");
ui.prompt("Publish", message.html(), "notice", [{
text: "cancel"
}, {
text: "publish",
primary: true,
handler: function () {
activatePublishPaths(ui, collection, publishPaths)
}
}])
}
})

function getPublishPaths(selections) {
return selections.flatMap(selection => Array.from(
selection.querySelectorAll('[data-publish-path]'))
.map(element => element.getAttribute('data-publish-path'))
.filter(value => value !== null)
);
}

function createEl(name) {
return $(document.createElement(name))
}

function activatePublishPaths(ui, collection, paths) {
$.ajax({
url: REPLICATE_URL,
type: "POST",
data: {
_charset_: "utf-8",
cmd: "Activate",
path: paths,
agentId: "publish"
}
}).always(function () {
ui.clearWait()
}).done(function () {
var api = $(collection).adaptTo("foundation-collection");
if (api && "reload" in api) {
api.reload();
ui.notify(null, getSuccessMessage(publishPaths));
return
}
var contentApi = $(".foundation-content").adaptTo("foundation-content");
if (contentApi)
contentApi.refresh();
ui.notify(null, getSuccessMessage(publishPaths))
}).fail(function (xhr) {
var title = Granite.I18n.get("Error");
var message = Granite.I18n.getVar($(xhr.responseText).find("#Message").html());
ui.alert(title, message, "error")
})
}

function getSuccessMessage(paths) {
var successMessage = Granite.I18n.get("{0} items have been published", paths.length);
if (paths.length === 1)
successMessage = Granite.I18n.get("The item has been published");
return successMessage
}
})();
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<td is="coral-table-cell" coral-table-rowselect></td>
<td is="coral-table-cell">${properties.key}</td>
<sly data-sly-repeat.language="${properties.languages}">
<td is="coral-table-cell">${properties[language]}</td>
<td is="coral-table-cell"
data-publish-path="${properties.messageEntryPaths[languageList.index]}">
${properties[language]}
</td>
</sly>
</tr>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
data-foundation-collection-navigator-href="/tools/translation/dictionaries/message-entries.html${resource.path}"
class="foundation-collection-item foundation-collection-navigator">
<td is="coral-table-cell" coral-table-rowselect></td>
<td is="coral-table-cell">${resource.path}</td>
<td is="coral-table-cell" data-publish-path="${resource.path}">${resource.path}</td>
<td is="coral-table-cell">${model.languageList}</td>
<td is="coral-table-cell">${model.lastModifiedFormatted}</td>
<td is="coral-table-cell">${model.basename}</td>
Expand Down
Loading

0 comments on commit 96e0151

Please sign in to comment.