Added basic connection with CQSM Servlets on dashboard to execute scripts
*/
(function (window, $) {
- $(window).adaptTo("foundation-registry").register("foundation.collection.action.action", {
+ $(window).adaptTo("foundation-registry").register(
+ "foundation.collection.action.action", {
name: "dashboard.view",
handler: function (name, el, config, collection, selections) {
var selected = selections[0].attributes['data-path'].value;
}
});
- $(window).adaptTo("foundation-registry").register("foundation.collection.action.action", {
+ $(window).adaptTo("foundation-registry").register(
+ "foundation.collection.action.action", {
name: "dashboard.dryrun",
handler: function (name, el, config, collection, selections) {
var selected = selections[0].attributes['data-path'].value;
- console.info('Implement Me: dryrun CLICK ' + selected);
+ runOnAuthor(selected, "DRY_RUN");
}
});
- $(window).adaptTo("foundation-registry").register("foundation.collection.action.action", {
+ $(window).adaptTo("foundation-registry").register(
+ "foundation.collection.action.action", {
name: "dashboard.runonauthor",
handler: function (name, el, config, collection, selections) {
var selected = selections[0].attributes['data-path'].value;
- console.info('Implement Me: runonauthor CLICK ' + selected);
+ runOnAuthor(selected, "RUN");
}
});
- $(window).adaptTo("foundation-registry").register("foundation.collection.action.action", {
+ $(window).adaptTo("foundation-registry").register(
+ "foundation.collection.action.action", {
name: "dashboard.runonpublish",
handler: function (name, el, config, collection, selections) {
var selected = selections[0].attributes['data-path'].value;
- console.info('Implement Me: runonpublish CLICK ' + selected);
+ runOnPublish(selected);
}
});
+ function runOnAuthor(scriptPath, mode) {
+
+ $.ajax({
+ type: "POST",
+ url: "/bin/cqsm/run-background?file=" + scriptPath + "&mode="
+ + mode,
+ dataType: "html",
+ success: function (data) {
+ var jobId = JSON.parse(data).id;
+
+ (function checkStatus(jobId) {
+ $.ajax({
+ type: "GET",
+ url: "/bin/cqsm/run-background?id=" + jobId,
+ dataType: "html",
+ success: function (data) {
+ var dataObject = JSON.parse(data);
+ if (dataObject.type === 'running') {
+ setTimeout(function () {
+ checkStatus(jobId)
+ }, 1000);
+ } else if (dataObject.type === 'finished') {
+ console.log(scriptPath + " finished: " + JSON.stringify(dataObject.entries));
+ console.log(
+ "Implement me: provide more sophisticated way of displaying results after finishing the script")
+ } else if (dataObject.type === 'unknown') {
+ console.log(
+ "Implement me: handle \"unknown\" case");
+ }
+ }
+ });
+ })(jobId);
+ }
+ });
+ }
+
+ function runOnPublish(fileName) {
+
+ $.ajax({
+ type: "GET",
+ url: "/bin/cqsm/replicate?run=publish&fileName=" + fileName,
+ dataType: "json",
+ success: function (data) {
+ console.log("publish response: " + JSON.stringify(data));
+ console.log("Implement me: handle \'publish\' case");
+ }
+ });
+ }
+
})(window, jQuery);
