Commit 4cd3dd36 authored by BaiJiangJie's avatar BaiJiangJie Committed by 老广

[Update] 更新RemoteApp (#2720)

* [Update] RemoteAppForm添加RemoteApp各类型参数保存逻辑

* [Update] RemoteApp添加默认应用路径
parent b18ca8c9
...@@ -8,6 +8,7 @@ from orgs.mixins import OrgModelForm ...@@ -8,6 +8,7 @@ from orgs.mixins import OrgModelForm
from assets.models import Asset, SystemUser from assets.models import Asset, SystemUser
from ..models import RemoteApp from ..models import RemoteApp
from .. import const
__all__ = [ __all__ = [
...@@ -109,3 +110,23 @@ class RemoteAppCreateUpdateForm(RemoteAppTypeForms, OrgModelForm): ...@@ -109,3 +110,23 @@ class RemoteAppCreateUpdateForm(RemoteAppTypeForms, OrgModelForm):
}) })
} }
def _clean_params(self):
app_type = self.data.get('type')
fields = const.REMOTE_APP_TYPE_MAP_FIELDS.get(app_type, [])
params = {}
for field in fields:
name = field['name']
value = self.cleaned_data[name]
params.update({name: value})
return params
def _save_params(self, instance):
params = self._clean_params()
instance.params = params
instance.save()
return instance
def save(self, commit=True):
instance = super().save(commit=commit)
instance = self._save_params(instance)
return instance
...@@ -64,28 +64,60 @@ ...@@ -64,28 +64,60 @@
{% block custom_foot_js %} {% block custom_foot_js %}
<script type="text/javascript"> <script type="text/javascript">
var type_id = '#' + '{{ form.type.id_for_label }}'; var app_type_id = '#' + '{{ form.type.id_for_label }}';
var app_path_id = '#' + '{{ form.path.id_for_label }}';
var all_type_fields = [ var all_type_fields = [
'.chrome-fields', '.chrome-fields',
'.mysql_workbench-fields', '.mysql_workbench-fields',
'.vmware_client-fields', '.vmware_client-fields',
'.custom-fields' '.custom-fields'
]; ];
function appTypeChange(){ var app_type_map_default_fields_value = {
'chrome': {
'app_path': 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe'
},
'mysql_workbench': {
'app_path': 'C:\\Program Files\\MySQL\\MySQL Workbench 8.0 CE\\MySQLWorkbench.exe'
},
'vmware_client': {
'app_path': ''
},
'custom': {'app_path': ''}
};
function getAppType(){
return $(app_type_id+ " option:selected").val();
}
function initialDefaultValue(){
var app_type = getAppType();
var app_path = $(app_path_id).val();
if(app_path){
app_type_map_default_fields_value[app_type]['app_path'] = app_path
}
}
function setDefaultValue(){
// 设置类型相关字段的默认值
var app_type = getAppType();
var app_path = app_type_map_default_fields_value[app_type]['app_path'];
$(app_path_id).val(app_path)
}
function hiddenFields(){
var app_type = getAppType();
$.each(all_type_fields, function(index, value){ $.each(all_type_fields, function(index, value){
$(value).addClass('hidden') $(value).addClass('hidden')
}); });
var type = $(type_id+ " option:selected").val(); $('.' + app_type + '-fields').removeClass('hidden');
$('.' + type + '-fields').removeClass('hidden');
} }
$(document).ready(function () { $(document).ready(function () {
$('.select2').select2({ $('.select2').select2({
closeOnSelect: true closeOnSelect: true
}); });
appTypeChange() initialDefaultValue();
hiddenFields();
setDefaultValue();
}) })
.on('change', type_id, function(){ .on('change', app_type_id, function(){
appTypeChange(); hiddenFields();
setDefaultValue();
}); });
</script> </script>
{% endblock %} {% endblock %}
\ No newline at end of file
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