Commit 0ce94a7b authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_jio: Draft implementation to replace "intent" API with a gadget.

parent 3ecbfd4d
<!DOCTYPE html>
<html>
<!--
data-i18n=Slapos
-->
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>Site List</title>
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_erp5_page_slap_intent.js" type="text/javascript"></script>
</head>
<body>
<form class="save_form ui-body-c" novalidate>
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline
ui-icon-edit ui-btn-icon-right ui-screen-hidden"></button>
<div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="form_view"
data-gadget-sandbox="public">
</div>
</form>
</body>
</html>
/*global window, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("jio_post", "jio_post")
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.allowPublicAcquisition('notifySubmit', function () {
return this.triggerSubmit();
})
.onEvent('submit', function () {
var gadget = this;
return gadget.notifySubmitting()
.push(function () {
return gadget.getDeclaredGadget('form_view');
})
.push(function (form_gadget) {
return form_gadget.getContent();
})
.push(function (doc) {
return gadget.getSetting("hateoas_url")
.push(function (url) {
return gadget.jio_putAttachment(doc.relative_url,
url + doc.relative_url + "/SoftwareRelease_requestHostingSubscription", doc);
});
})
.push(function (key) {
return gadget.notifySubmitted({message: 'New service created.', status: 'success'})
.push(function () {
// Workaround, find a way to open document without break gadget.
return gadget.redirect({"command": "change",
"options": {"jio_key": "/", "page": "slap_service_list"}});
});
});
})
.declareMethod("triggerSubmit", function () {
return this.element.querySelector('button[type="submit"]').click();
})
.declareMethod("render", function (options) {
var gadget = this;
if (options.intent !== "request") {
throw new Error("Intent not supported");
}
return RSVP.Queue()
.push(function () {
return gadget.updateHeader({
page_title: "Requesting a service..."
});
})
.push(function () {
return gadget.getSetting("hateoas_url")
.push(function (url) {
return gadget.jio_getAttachment("/",
url + "/SoftwareProduct_getSoftwareReleaseAsHateoas?software_release=" + options.software_release
);
});
})
.push(function (jio_key) {
if (options.auto === undefined) {
return gadget.redirect({"command": "change",
"options": {"jio_key": jio_key, "page": "slap_add_hosting_subscription",
"title": options.title}});
}
// The auto is set, so we move foward to auto request the SR
options.jio_key = jio_key;
return RSVP.all([
gadget.getDeclaredGadget('form_view'),
gadget.jio_get(jio_key),
gadget.getSetting("hateoas_url")
]);
})
.push(function (result) {
var software_release = result[1],
url = result[2],
title = options.software_title ? options.software_title: "Instance ",
doc = {};
doc.url_string = software_release.url_string;
doc.title = title;
doc.text_content = "";
doc.relative_url = options.jio_key;
return gadget.notifySubmitting()
.push(function () {
return gadget.jio_putAttachment(doc.relative_url,
url + doc.relative_url + "/SoftwareRelease_requestHostingSubscription", doc);
})
.push(function (key) {
return gadget.notifySubmitted({message: 'New service created.', status: 'success'})
.push(function () {
// Workaround, find a way to open document without break gadget.
return gadget.redirect({"command": "change",
"options": {"jio_key": "/", "page": "slap_service_list"}});
});
});
});
});
}(window, rJS, RSVP));
\ No newline at end of file
import json
if software_release.startswith("product."):
software_release_list = context.SoftwareProduct_getSortedSoftwareReleaseList(software_product_reference=software_release[8:])
else:
software_release_list = context.SoftwareProduct_getSortedSoftwareReleaseList(software_release_url=software_release)
if len(software_release_list):
software_release_document = software_release_list[0]
return json.dumps(software_release_document.getRelativeUrl())
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>software_release</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SoftwareProduct_getSoftwareReleaseAsHateoas</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -5,6 +5,8 @@ web_page_module/rjs_gadget_erp5_page_slap_transfer_computer_html
web_page_module/rjs_gadget_erp5_page_map_html
web_page_module/rjs_gadget_slapos_appcache
web_page_module/rjs_gadget_erp5_page_map_js
web_page_module/rjs_gadget_erp5_page_slap_intent_js
web_page_module/rjs_gadget_erp5_page_slap_intent_html
web_page_module/rjs_gadget_erp5_page_slap_add_computer_html
web_page_module/rjs_gadget_erp5_page_slap_add_computer_js
web_page_module/rjs_gadget_erp5_page_slap_add_hosting_subscription_html
......
......@@ -40,6 +40,8 @@ web_page_module/rjs_gadget_erp5_page_slap_destroy_software_installation_html
web_page_module/rjs_gadget_erp5_page_slap_destroy_software_installation_js
web_page_module/rjs_gadget_erp5_page_slap_hosting_subscription_view_html
web_page_module/rjs_gadget_erp5_page_slap_hosting_subscription_view_js
web_page_module/rjs_gadget_erp5_page_slap_intent_html
web_page_module/rjs_gadget_erp5_page_slap_intent_js
web_page_module/rjs_gadget_erp5_page_slap_invoice_list_html
web_page_module/rjs_gadget_erp5_page_slap_invoice_list_js
web_page_module/rjs_gadget_erp5_page_slap_load_schema_html
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment