1
0
mirror of https://github.com/dkmstr/openuds.git synced 2024-12-22 13:34:04 +03:00

Done multi tab forms

Advancing on Transport new/edit (this & network will server as base for other tabs)
This commit is contained in:
Adolfo Gómez 2013-11-27 00:41:03 +00:00
parent fa2335efd4
commit d46400c1f7
7 changed files with 54 additions and 21 deletions

View File

@ -56,11 +56,11 @@ class Transports(ModelHandlerMixin, Handler):
'comments': item.comments, 'comments': item.comments,
'priority': item.priority, 'priority': item.priority,
'nets_positive': item.nets_positive, 'nets_positive': item.nets_positive,
'networks': [ {'id': k.id} for k in item.networks.all() ],
'deployed_count': item.deployedServices.count(), 'deployed_count': item.deployedServices.count(),
'type': type_.type(), 'type': type_.type(),
} }
class Types(ModelTypeHandlerMixin, Handler): class Types(ModelTypeHandlerMixin, Handler):
path = 'transports' path = 'transports'
@ -78,7 +78,7 @@ class Types(ModelTypeHandlerMixin, Handler):
'label': ugettext('Priority'), 'label': ugettext('Priority'),
'tooltip': ugettext('Priority of this transport'), 'tooltip': ugettext('Priority of this transport'),
'type': 'numeric', 'type': 'numeric',
'order': 100, # At end 'order': -50, # At end
}) })
except: except:
raise NotFound('type not found') raise NotFound('type not found')

View File

@ -226,7 +226,7 @@ class ModelTypeHandlerMixin(object):
'required': True, 'required': True,
'label': _('Name'), 'label': _('Name'),
'tooltip': _('Name of this element'), 'tooltip': _('Name of this element'),
'order': -2, 'order': -100,
}) })
# And maybe comments (only if model has this field) # And maybe comments (only if model has this field)
if 'comments' in flds: if 'comments' in flds:
@ -235,7 +235,7 @@ class ModelTypeHandlerMixin(object):
'label': _('Comments'), 'label': _('Comments'),
'tooltip': _('Comments for this element'), 'tooltip': _('Comments for this element'),
'length': 256, 'length': 256,
'order': -1, 'order': -99,
}) })
return gui return gui

View File

@ -32,7 +32,7 @@
''' '''
from __future__ import unicode_literals from __future__ import unicode_literals
#from django.utils import simplejson #from django.utils import simplejson as json
import ujson as json import ujson as json
from django import http from django import http

View File

@ -13,4 +13,4 @@ class XUACompatibleMiddleware(object):
def process_response(self, request, response): def process_response(self, request, response):
if response.get('content-type', '').startswith('text/html'): if response.get('content-type', '').startswith('text/html'):
response['X-UA-Compatible'] = 'IE=edge' response['X-UA-Compatible'] = 'IE=edge'
return response return response

View File

@ -145,24 +145,48 @@ gui.connectivity.link = function(event) {
onEdit: function(value, event, table, refreshFnc) { onEdit: function(value, event, table, refreshFnc) {
gui.connectivity.transports.rest.gui(value.type, function(itemGui){ gui.connectivity.transports.rest.gui(value.type, function(itemGui){
gui.connectivity.transports.rest.item(value.id, function(item) { gui.connectivity.transports.rest.item(value.id, function(item) {
var form = gui.form.fromFields(itemGui, item); var tabs = {
gui.launchModalForm(gettext('Edit transport')+' '+value.name,form, function(form_selector, closeFnc) { tabs: [
var fields = gui.form.read(form_selector); {
fields.data_type = value.type; title: 'General',
fields.nets_positive = false; fields: itemGui,
gui.connectivity.transports.rest.save(fields, function(data) { // Success on put },
closeFnc(); {
refreshFnc(); title: 'Networks',
}, gui.failRequestModalFnc(gettext('Error creating transport')) // Fail on put, show modal message fields: [],
); },
return false; ]
}); };
var form = gui.form.fromFields(tabs, item);
gui.launchModalForm(gettext('Edit transport')+' '+value.name,form, function(form_selector, closeFnc) {
var fields = gui.form.read(form_selector);
fields.data_type = value.type;
fields.nets_positive = false;
gui.connectivity.transports.rest.save(fields, function(data) { // Success on put
closeFnc();
refreshFnc();
}, gui.failRequestModalFnc(gettext('Error creating transport')) // Fail on put, show modal message
);
return false;
}); });
});
}); });
}, },
onNew: function(type, table, refreshFnc) { onNew: function(type, table, refreshFnc) {
gui.connectivity.transports.rest.gui(type, function(itemGui) { gui.connectivity.transports.rest.gui(type, function(itemGui) {
var form = gui.form.fromFields(itemGui); var tabs = {
tabs: [
{
title: 'General',
fields: itemGui,
},
{
title: 'Networks',
fields: [],
},
]
};
var form = gui.form.fromFields(tabs);
gui.launchModalForm(gettext('New transport'), form, function(form_selector, closeFnc) { gui.launchModalForm(gettext('New transport'), form, function(form_selector, closeFnc) {
var fields = gui.form.read(form_selector); var fields = gui.form.read(form_selector);
// Append "own" fields, in this case data_type // Append "own" fields, in this case data_type

View File

@ -38,7 +38,16 @@
var form = '<form class="form-horizontal" role="form">' + var form = '<form class="form-horizontal" role="form">' +
'<input type="hidden" name="id" class="modal_field_data" value="' + item.id + '">'; '<input type="hidden" name="id" class="modal_field_data" value="' + item.id + '">';
if( fields.tabs ) { if( fields.tabs ) {
var id = 'tab-' + Math.random().toString().split('.')[1]; // Get a random base ID for tab entries
var tabs = [];
var tabsContent = [];
var active = ' active in' ;
$.each(fields.tabs, function(index, tab){
tabsContent.push('<div class="tab-pane fade' + active + '" id="' + id + index + '">' + gui.fieldsToHtml(tab.fields, item) + '</div>' );
tabs.push('<li><a href="#' + id + index + '" data-toggle="tab">' + tab.title + '</a></li>' );
active = '';
});
form += '<ul class="nav nav-tabs">' + tabs.join('\n') + '</ul><div class="tab-content">' + tabsContent.join('\n') + '</div>';
} else { } else {
form += gui.fieldsToHtml(fields, item, editing); form += gui.fieldsToHtml(fields, item, editing);
} }

View File

@ -119,7 +119,7 @@
}; };
gui.launchModalForm = function(title, form, onSuccess) { gui.launchModalForm = function(title, form, onSuccess) {
var id = Math.random().toString().split('.')[1]; // Get a random ID for this modal var id = 'modal-' + Math.random().toString().split('.')[1]; // Get a random ID for this modal
gui.appendToWorkspace(gui.modal(id, title, form)); gui.appendToWorkspace(gui.modal(id, title, form));
id = '#' + id; // for jQuery id = '#' + id; // for jQuery