Commit 76618994 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_jio&cloud: Use Person.requestSupport() API

parent c4f14884
...@@ -9,8 +9,10 @@ try: ...@@ -9,8 +9,10 @@ try:
support_request_title = kwargs['support_request_title'] support_request_title = kwargs['support_request_title']
resource = kwargs['support_request_resource'] resource = kwargs['support_request_resource']
description = kwargs['support_request_description'] description = kwargs['support_request_description']
# Aggregate can be None, so it isn't included on the kwargs
aggregate = kwargs.get("support_request_aggregate", None)
except KeyError: except KeyError:
raise TypeError, "Person_requestSupportRequest takes exactly 1 argument" raise TypeError, "Person_requestSupportRequest takes exactly 4 arguments"
tag = "%s_%s_SupportRequestInProgress" % (person.getUid(), tag = "%s_%s_SupportRequestInProgress" % (person.getUid(),
support_request_title) support_request_title)
...@@ -28,6 +30,7 @@ support_request = module.newContent( ...@@ -28,6 +30,7 @@ support_request = module.newContent(
description=description, description=description,
resource=resource, resource=resource,
destination_decision_value=person, destination_decision_value=person,
aggregate=aggregate,
specialise="sale_trade_condition_module/slapos_ticket_trade_condition", specialise="sale_trade_condition_module/slapos_ticket_trade_condition",
activate_kw={'tag': tag} activate_kw={'tag': tag}
) )
......
...@@ -11,9 +11,10 @@ ...@@ -11,9 +11,10 @@
.declareAcquiredMethod("updatePanel", "updatePanel") .declareAcquiredMethod("updatePanel", "updatePanel")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment") .declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("getSetting", "getSetting") .declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("getSettingList", "getSettingList")
.declareAcquiredMethod("getUrlFor", "getUrlFor") .declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("redirect", "redirect") .declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("jio_post", "jio_post") .declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("jio_get", "jio_get") .declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting") .declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted') .declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
...@@ -26,6 +27,7 @@ ...@@ -26,6 +27,7 @@
return this.triggerSubmit(); return this.triggerSubmit();
}) })
.onEvent('submit', function () { .onEvent('submit', function () {
var gadget = this; var gadget = this;
return gadget.notifySubmitting() return gadget.notifySubmitting()
...@@ -33,28 +35,31 @@ ...@@ -33,28 +35,31 @@
return gadget.getDeclaredGadget('form_view'); return gadget.getDeclaredGadget('form_view');
}) })
.push(function (form_gadget) { .push(function (form_gadget) {
return form_gadget.getContent(); return RSVP.all([form_gadget.getContent(),
gadget.getSettingList(['me', 'hateoas_url'])]);
}) })
.push(function (content) { .push(function (result) {
var property, doc = {}; var doc = result[0],
for (property in content) { me = result[1][0],
if ((content.hasOwnProperty(property)) && url = result[1][1];
// Remove undefined keys added by Gadget fields return gadget.jio_putAttachment(me,
(property !== "undefined") && url + me + "/Person_requestSupport",
// Remove default_*:int keys added by ListField {title: doc.title,
!(property.endsWith(":int") && property.startsWith("default_"))) { description: doc.description,
doc[property] = content[property]; resource: doc.resource});
} })
.push(function (attachment) {
} return jIO.util.readBlobAsText(attachment.target.response);
return gadget.jio_post(doc);
}) })
.push(function (key) { .push(function (response) {
return JSON.parse(response.target.result);
})
.push(function (result) {
return gadget.notifySubmitted({message: gadget.message_translation, status: 'success'}) return gadget.notifySubmitted({message: gadget.message_translation, status: 'success'})
.push(function () { .push(function () {
// Workaround, find a way to open document without break gadget. // Workaround, find a way to open document without break gadget.
return gadget.redirect({"command": "change", return gadget.redirect({"command": "change",
"options": {"jio_key": key, "page": "slap_controller"}}); "options": {"jio_key": result.relative_url, "page": "slap_controller"}});
}); });
}); });
}) })
...@@ -88,20 +93,19 @@ ...@@ -88,20 +93,19 @@
gadget.getDeclaredGadget('form_view'), gadget.getDeclaredGadget('form_view'),
gadget.jio_getAttachment("ticket_resource_list", gadget.jio_getAttachment("ticket_resource_list",
hateoas_url + "Ticket_getResourceItemListAsJSON"), hateoas_url + "Ticket_getResourceItemListAsJSON"),
window.getSettingMe(gadget),
gadget.getTranslationList(translation_list) gadget.getTranslationList(translation_list)
]); ]);
}) })
.push(function (result) { .push(function (result) {
gadget.message_translation = result[3][0]; gadget.message_translation = result[2][0];
page_title_translation = result[3][10]; page_title_translation = result[2][10];
return result[0].render({ return result[0].render({
erp5_document: { erp5_document: {
"_embedded": {"_view": { "_embedded": {"_view": {
"my_title": { "my_title": {
"description": result[3][1], "description": result[2][1],
"title": result[3][2], "title": result[2][2],
"default": "", "default": "",
"css_class": "", "css_class": "",
"required": 1, "required": 1,
...@@ -112,7 +116,7 @@ ...@@ -112,7 +116,7 @@
}, },
"my_description": { "my_description": {
"description": "", "description": "",
"title": result[3][3], "title": result[2][3],
"default": "", "default": "",
"css_class": "", "css_class": "",
"required": 1, "required": 1,
...@@ -122,8 +126,8 @@ ...@@ -122,8 +126,8 @@
"type": "TextAreaField" "type": "TextAreaField"
}, },
"my_resource": { "my_resource": {
"description": result[3][0], "description": result[2][0],
"title": result[3][4], "title": result[2][4],
"default": "", "default": "",
"items": result[1], "items": result[1],
"css_class": "", "css_class": "",
...@@ -132,52 +136,6 @@ ...@@ -132,52 +136,6 @@
"key": "resource", "key": "resource",
"hidden": 0, "hidden": 0,
"type": "ListField" "type": "ListField"
},
"my_destination_decision": {
"description": result[3][0],
"title": result[3][5],
"default": result[2],
"css_class": "",
"required": 1,
"editable": 1,
"key": "destination_decision",
"hidden": 1,
"type": "StringField"
},
"my_specialise": {
"description": "",
"title": result[3][6],
// Auto Set a hardcoded trade Condition
// Please replace it by a getSetting.
"default": "sale_trade_condition_module/slapos_ticket_trade_condition",
"css_class": "",
"required": 1,
"editable": 1,
"key": "specialise",
"hidden": 1,
"type": "StringField"
},
"my_portal_type": {
"description": result[3][0],
"title": result[3][7],
"default": "Support Request",
"css_class": "",
"required": 1,
"editable": 1,
"key": "portal_type",
"hidden": 1,
"type": "StringField"
},
"my_parent_relative_url": {
"description": "",
"title": result[3][9],
"default": "support_request_module",
"css_class": "",
"required": 1,
"editable": 1,
"key": "parent_relative_url",
"hidden": 1,
"type": "StringField"
} }
}}, }},
"_links": { "_links": {
...@@ -193,7 +151,7 @@ ...@@ -193,7 +151,7 @@
[["my_resource"]] [["my_resource"]]
], [ ], [
"center", "center",
[["my_title"], ["my_description"], ["my_specialise"], ["my_destination_decision"], ["my_portal_type"], ["my_parent_relative_url"]] [["my_title"], ["my_description"]]
]] ]]
} }
}); });
......
...@@ -279,7 +279,7 @@ ...@@ -279,7 +279,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>987.11835.35244.22135</string> </value> <value> <string>997.18055.28455.10120</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -297,7 +297,7 @@ ...@@ -297,7 +297,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1602260862.83</float> <float>1641264462.37</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
import json
portal = context.getPortalObject()
person = portal.portal_membership.getAuthenticatedMember().getUserValue()
request = context.REQUEST
response = request.RESPONSE
if person is None:
response.setStatus(403)
else:
request_kw = {"support_request_title": title,
"support_request_description": description,
"support_request_resource": resource,
"support_request_aggregate": aggregate}
person.requestSupport(**request_kw)
support_relative_url = request.get('support_request_relative_url')
response.setHeader('Content-Type', "application/json")
return json.dumps({
"relative_url": support_relative_url
})
<?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>title, description, resource, aggregate=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Person_requestSupport</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ZopePageTemplate" module="Products.PageTemplates.ZopePageTemplate"/>
</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>
<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>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>expand</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>testSlapOSJSServerTicketRelated</string> </value>
</item>
<item>
<key> <string>output_encoding</string> </key>
<value> <string>utf-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <unicode></unicode> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ZopePageTemplate" module="Products.PageTemplates.ZopePageTemplate"/>
</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>
<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>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>expand</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>testSlapOSJSServiceTicketRelated</string> </value>
</item>
<item>
<key> <string>output_encoding</string> </key>
<value> <string>utf-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <unicode></unicode> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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