[Update] 创建/更新 远程应用 使用api (#2940)

* [Update] 创建/更新 远程应用 使用api

* [Update] 优化 params

* [Update] 修改小问题
pull/2945/head
八千流 5 years ago committed by BaiJiangJie
parent ab9744d529
commit 9219786f2d

@ -107,6 +107,18 @@ function hiddenFields(){
});
$('.' + app_type + '-fields').removeClass('hidden');
}
function constructParams(obj) {
var type = ['chrome', 'mysql_workbench', 'vmware_client', 'custom'];
var params = {};
type.forEach(function (attr) {
if (obj.type === attr){
for (var k in obj){
if (k.startsWith(obj.type)){params[k] = obj[k]}
}
}
});
return params
}
$(document).ready(function () {
$('.select2').select2({
closeOnSelect: true
@ -118,6 +130,28 @@ $(document).ready(function () {
.on('change', app_type_id, function(){
hiddenFields();
setDefaultValue();
});
})
.on("submit", "form", function (evt) {
evt.preventDefault();
var the_url = '{% url "api-applications:remote-app-list" %}';
var redirect_to = '{% url "applications:remote-app-list" %}';
var method = "POST";
{% if type == "update" %}
the_url = '{% url "api-applications:remote-app-detail" object.id %}';
method = "PUT";
{% endif %}
var form = $("form");
var data = form.serializeObject();
data["params"] = constructParams(data);
var props = {
url: the_url,
data: data,
method: method,
form: form,
redirect_to: redirect_to
};
formSubmit(props);
})
;
</script>
{% endblock %}

@ -46,6 +46,7 @@ class RemoteAppCreateView(PermissionsMixin, SuccessMessageMixin, CreateView):
context = {
'app': _('Applications'),
'action': _('Create RemoteApp'),
'type': 'create'
}
kwargs.update(context)
return super().get_context_data(**kwargs)
@ -68,6 +69,7 @@ class RemoteAppUpdateView(PermissionsMixin, SuccessMessageMixin, UpdateView):
context = {
'app': _('Applications'),
'action': _('Update RemoteApp'),
'type': 'update'
}
kwargs.update(context)
return super().get_context_data(**kwargs)

Loading…
Cancel
Save