From 9219786f2dbb6e661bc60357a85541fd4c55e867 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=AB=E5=8D=83=E6=B5=81?= <40739051+jym503558564@users.noreply.github.com> Date: Mon, 15 Jul 2019 14:42:54 +0800 Subject: [PATCH] =?UTF-8?q?[Update]=20=E5=88=9B=E5=BB=BA/=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=20=E8=BF=9C=E7=A8=8B=E5=BA=94=E7=94=A8=20=E4=BD=BF?= =?UTF-8?q?=E7=94=A8api=20(#2940)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Update] 创建/更新 远程应用 使用api * [Update] 优化 params * [Update] 修改小问题 --- .../remote_app_create_update.html | 36 ++++++++++++++++++- apps/applications/views/remote_app.py | 2 ++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/apps/applications/templates/applications/remote_app_create_update.html b/apps/applications/templates/applications/remote_app_create_update.html index ecd7254a1..fe6b231da 100644 --- a/apps/applications/templates/applications/remote_app_create_update.html +++ b/apps/applications/templates/applications/remote_app_create_update.html @@ -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); + }) +; {% endblock %} \ No newline at end of file diff --git a/apps/applications/views/remote_app.py b/apps/applications/views/remote_app.py index 5576ed3bb..e7f6f0ccd 100644 --- a/apps/applications/views/remote_app.py +++ b/apps/applications/views/remote_app.py @@ -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)