Commit 56c433b3 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_jio: Implement UI for Cloud Contract

    User can view his Cloud Contract and its consumption.
parent 3910398c
<!DOCTYPE html>
<html>
<!--
data-i18n=Your Account
-->
<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_slapos_utils.js" type="text/javascript"></script>
<script src="gadget_erp5_page_slap_cloud_contract_view.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, jIO, Blob */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getUrlParameter", "getUrlParameter")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("updateDocument", "updateDocument")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("getTranslationList", "getTranslationList")
.allowPublicAcquisition("jio_allDocs", function (param_list) {
var gadget = this;
return gadget.jio_allDocs(param_list[0])
.push(function (result) {
var i, value, len = result.data.total_rows;
for (i = 0; i < len; i += 1) {
if (1 || (result.data.rows[i].value.hasOwnProperty("price_currency_title"))) {
value = result.data.rows[i].value.price_currency_title;
result.data.rows[i].value.price_currency_title = {
field_gadget_param : {
css_class: "",
"default": value,
key: "status",
editable: 1,
url: "gadget_slapos_label_listbox_field.html",
title: gadget.title_translation,
type: "GadgetField"
}
};
value = result.data.rows[i].value.maximum_invoice_credit;
result.data.rows[i].value.maximum_invoice_credit = {
field_gadget_param : {
css_class: "",
"default": value ? value.toString() : "0.0",
key: "status",
editable: 1,
url: "gadget_slapos_label_listbox_field.html",
title: gadget.title_translation,
type: "GadgetField"
}
};
value = result.data.rows[i].value.CloudContractLine_getRemainingInvoiceCredit;
result.data.rows[i].value.CloudContractLine_getRemainingInvoiceCredit = {
field_gadget_param : {
css_class: "",
"default": value ? value.toString() : "0.0",
key: "status",
editable: 1,
url: "gadget_slapos_label_listbox_field.html",
title: gadget.title_translation,
type: "GadgetField"
}
};
result.data.rows[i].value["listbox_uid:list"] = {
key: "listbox_uid:list",
value: 2713
};
}
}
return result;
});
})
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("render", function (options) {
return this.changeState({
jio_key: options.jio_key,
doc: options.doc,
editable: 1
});
})
.onStateChange(function () {
var gadget = this,
translation_list = [
"Maximum Invoice Delay",
"Maximum Credit",
"Cloud Contract",
"Currency",
"Maximum Credit per Currency",
"Remaining Credit"
];
return gadget.getSetting("hateoas_url")
.push(function (url) {
return RSVP.all([
gadget.getDeclaredGadget('form_view'),
gadget.getTranslationList(translation_list)
]);
})
.push(function (result) {
gadget.account_translation = result[1][2];
var form_gadget = result[0],
column_list = [
['price_currency_title', result[1][3]],
['maximum_invoice_credit', result[1][1]],
['CloudContractLine_getRemainingInvoiceCredit', result[1][5]]
];
return form_gadget.render({
erp5_document: {
"_embedded": {"_view": {
"my_maximum_invoice_delay": {
"description": "",
"title": result[1][0],
"default": gadget.state.doc.maximum_invoice_delay,
"css_class": "",
"required": 1,
"editable": 0,
"key": "maximum_invoice_delay",
"hidden": 0,
"type": "FloatField"
},
"listbox": {
"column_list": column_list,
"show_anchor": 0,
"default_params": {},
"editable": 1,
"editable_column_list": [],
"key": "slap_cloud_contract_line_listbox",
"lines": 20,
"list_method": "portal_catalog",
"query": "urn:jio:allDocs?query=%28portal_type%3A%28%22" +
"Cloud Contract Line" + "%22%29%29",
"portal_type": [],
"search_column_list": column_list,
"sort_column_list": column_list,
"sort": [],
"title": result[1][4],
"type": "ListBox"
}
}},
"_links": {
"type": {
// form_list display portal_type in header
name: ""
}
}
},
form_definition: {
group_list: [[
"left",
[["my_maximum_invoice_delay"]]
], [
"bottom",
[["listbox"]]
]]
}
});
})
.push(function () {
return RSVP.all([
gadget.getUrlFor({ command: 'change', options: { page: 'slap_person_view', jio_key: '' } })
]);
})
.push(function (result) {
var header_dict = {
page_title: gadget.account_translation + " : " + gadget.state.doc.destination_section_title,
selection_url: result[0]
};
return gadget.updateHeader(header_dict);
});
});
}(window, rJS, RSVP));
\ No newline at end of file
......@@ -18,6 +18,7 @@
<script src="renderjs.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_slapos_utils.js" type="text/javascript"></script>
<script src="gadget_erp5_page_slap_invoice_list.js" type="text/javascript"></script>
</head>
......
......@@ -12,6 +12,8 @@
.declareAcquiredMethod("setSetting", "setSetting")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("getTranslationList", "getTranslationList")
.allowPublicAcquisition("jio_allDocs", function (param_list) {
......@@ -169,13 +171,27 @@
})
.push(function () {
return RSVP.all([
gadget.getUrlFor({command: "change", options: {"page": "slapos"}})
gadget.getSetting("hateoas_url"),
window.getSettingMe(gadget)
]);
})
.push(function (url_list) {
return gadget.jio_getAttachment("contract_relative_url",
url_list[0] + url_list[1] + "/Person_getCloudContractRelated?return_json=True");
})
.push(function (contract_relative_url) {
return RSVP.all([
gadget.getUrlFor({command: "change", options: {"page": "slapos"}}),
gadget.getUrlFor({command: "change", options: {"jio_key": contract_relative_url,
"page": "slap_controller"}})
]);
})
.push(function (result) {
return gadget.updateHeader({
page_title: invoices_translation,
selection_url: result[0],
contract_url: result[1],
filter_action: true
});
});
......
......@@ -316,7 +316,8 @@
gadget.getUrlFor({command: "change", options: {jio_key: me, page: "slap_person_get_token"}}),
gadget.getUrlFor({command: "change", options: {jio_key: me, page: "slap_person_add_erp5_login"}}),
gadget.getUrlFor({command: "change", options: {jio_key: me, page: "slap_person_add_organisation"}}),
gadget.getUrlFor({command: "change", options: {page: "slapos"}})
gadget.getUrlFor({command: "change", options: {page: "slapos"}}),
gadget.getUrlFor({command: "change", options: {jio_key: gadget.state.doc.contract_relative_url, page: "slap_controller"}})
]);
})
.push(function (result) {
......@@ -330,6 +331,9 @@
add_organisation_url: result[5],
selection_url: result[6]
};
if (gadget.state.doc.contract_relative_url) {
header_dict.contract_url = result[7];
}
if (!gadget.state.editable) {
header_dict.edit_content = result[0];
}
......
......@@ -55,7 +55,8 @@
['supply_url', 'Supply', 'plus'],
['transfer_url', 'Transfer', 'exchange'],
['accept_url', 'Accept', 'check-circle'],
['reject_url', 'Reject', 'ban']
['reject_url', 'Reject', 'ban'],
['contract_url', 'Contract', 'usd']
],
header_button_template = function (data) {
// <form><button name='{{name}}' data-i18n="{{title}}" type='submit' class='ui-icon-{{icon}} ui-btn-icon-left {{class}}'>{{title}}</button></form>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ERP5 Form" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<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/>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>action</string> </key>
<value> <string>Base_edit</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>edit_order</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>enctype</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>group_list</string> </key>
<value>
<list>
<string>normal</string>
<string>left</string>
<string>right</string>
<string>normal width100</string>
<string>hidden</string>
</list>
</value>
</item>
<item>
<key> <string>groups</string> </key>
<value>
<dictionary>
<item>
<key> <string>hidden</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>left</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>normal</string> </key>
<value>
<list>
<string>my_maximum_invoice_delay</string>
<string>my_destination_section_title</string>
</list>
</value>
</item>
<item>
<key> <string>normal width100</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>right</string> </key>
<value>
<list/>
</value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>CloudContract_viewAsHateoas</string> </value>
</item>
<item>
<key> <string>method</string> </key>
<value> <string>POST</string> </value>
</item>
<item>
<key> <string>name</string> </key>
<value> <string>WebSection_viewMyAccountRender</string> </value>
</item>
<item>
<key> <string>pt</string> </key>
<value> <string>form_view_editable</string> </value>
</item>
<item>
<key> <string>row_length</string> </key>
<value> <int>4</int> </value>
</item>
<item>
<key> <string>stored_encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>unicode_mode</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>update_action</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>update_action_title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal = context.getPortalObject()
import json
contract = portal.portal_catalog.getResultValue(
portal_type="Cloud Contract",
default_destination_section_uid=context.getUid(),
validation_state=['invalidated', 'validated'],
)
if contract is not None:
if return_json:
return json.dumps(contract.getRelativeUrl())
return contract.getRelativeUrl()
if return_json:
return json.dumps("")
return
<?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>return_json=False</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Person_getCloudContractRelated</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -99,6 +99,7 @@
<string>my_default_address_zip_code</string>
<string>my_career_subordination_title</string>
<string>my_default_telephone_coordinate_text</string>
<string>my_contract_relative_url</string>
</list>
</value>
</item>
......
......@@ -55,6 +55,8 @@ url_list = [
"gadget_erp5_page_slap_computer_revoke_certificate.js",
"gadget_erp5_page_slap_computer_view.html",
"gadget_erp5_page_slap_computer_view.js",
"gadget_erp5_page_slap_cloud_contract_view.js",
"gadget_erp5_page_slap_cloud_contract_view.html",
"gadget_erp5_page_slap_controller.html",
"gadget_erp5_page_slap_controller.js",
"gadget_erp5_page_slap_delete_network.html",
......
image_module/gadget_slapos_panel_png
image_module/gadget_slapos_invoice_logo_png
web_page_module/gadget_erp5_page_slap_cloud_contract_view_html
web_page_module/gadget_erp5_page_slap_cloud_contract_view_js
web_page_module/gadget_erp5_page_slap_reject_upgrade_decision_html
web_page_module/gadget_erp5_page_slap_reject_upgrade_decision_js
web_page_module/rjs_gadget_erp5_attention_point_css
......
image_module/gadget_slapos_invoice_logo_png
image_module/gadget_slapos_panel_png
web_page_module/gadget_erp5_page_slap_cloud_contract_view_html
web_page_module/gadget_erp5_page_slap_cloud_contract_view_js
web_page_module/gadget_erp5_page_slap_reject_upgrade_decision_html
web_page_module/gadget_erp5_page_slap_reject_upgrade_decision_js
web_page_module/rjs_gadget_erp5_attention_point_css
......
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