Commit 97277697 by Kálmán Viktor

network: create record button from domain edit

parent 44798159
......@@ -20,3 +20,10 @@ function getCookie(name) {
}
return cookieValue;
}
function getURLParameter(name) {
return decodeURI(
(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
);
}
......@@ -255,6 +255,41 @@ function resetName() {
}
/*
* error creating function
*
* first it removes the current error message, then it iterates through
* all the given messages
*/
function appendMessage(type, messages, id) {
$('#js_error').remove();
resetErrors();
message = '<div id="js_error" style="display: none;" class="alert alert-danger"><ul>'
for(var i = 0;i < messages.length; i++) {
message += "<li>" +messages[i].message+ "</li>";
if(messages[i].id) {
$('#id_' + messages[i].id).closest('div[class="form-group"]').addClass("has-error");
}
}
message +='</ul></div>';
$('form').before(message);
$('html, body').animate({ scrollTop: 0}, 'slow', function() {
$('#js_error').fadeIn();
});
}
// remove error class from forms if we click on them
// it also removes the help-inline span that shouldn't really appear
$('* [id^="id_"]').focus(function() {
id = "#div_" + $(this).prop('id');
if($(id).hasClass('has-error')) {
$(id).removeClass('has-error');
$('span[id="error_1_' + $(this).attr('id') + '"]').remove();
}
});
// on page load
// if we are upadting
// - set the name and address
......@@ -268,6 +303,10 @@ $(function() {
}
// else we are creaing a new
else {
domain = getURLParameter('domain');
if(domain != 'null' && domain.length > 0) {
new_record = false;
} else {
new_record = true;
// hide all input containers
$('div[id^="div_id_"]').hide();
......@@ -284,6 +323,7 @@ $(function() {
);
$('#div_id_type').fadeIn();
}
}
});
// if the user choose a type
......@@ -303,38 +343,3 @@ function type_next() {
}
return false;
}
/*
* error creating function
*
* first it removes the current error message, then it iterates through
* all the given messages
*/
function appendMessage(type, messages, id) {
$('#js_error').remove();
resetErrors();
message = '<div id="js_error" style="display: none;" class="alert alert-danger"><ul>'
for(var i = 0;i < messages.length; i++) {
message += "<li>" +messages[i].message+ "</li>";
if(messages[i].id) {
$('#id_' + messages[i].id).closest('div[class="form-group"]').addClass("has-error");
}
}
message +='</ul></div>';
$('form').before(message);
$('html, body').animate({ scrollTop: 0}, 'slow', function() {
$('#js_error').fadeIn();
});
}
// remove error class from forms if we click on them
// it also removes the help-inline span that shouldn't really appear
$('* [id^="id_"]').focus(function() {
id = "#div_" + $(this).prop('id');
if($(id).hasClass('has-error')) {
$(id).removeClass('has-error');
$('span[id="error_1_' + $(this).attr('id') + '"]').remove();
}
});
......@@ -16,10 +16,10 @@
{% crispy form %}
</div>
<div class="col-sm-6 col-sm-offset-1">
<h3>
{% trans "List of this domain's records" %}
</h3>
<hr />
<div class="page-header">
<a href="{% url "network.record_create" %}?domain={{ domain_pk }}" class="btn btn-success pull-right btn-xs"><i class="icon-plus-sign"></i> {% trans "Add new record" %}</a>
<h3>{% trans "List of this domain's records" %}</h3>
</div>
<div class="table-responsive">
{% render_table record_list %}
</div>
......
......@@ -459,6 +459,12 @@ class RecordCreate(CreateView, SuccessMessageMixin):
# TODO fqdn
success_message = _(u'Successfully created record!')
def get_initial(self):
return {
# 'owner': 1,
'domain': self.request.GET.get('domain'),
}
class RecordDelete(DeleteView):
model = Record
......
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 sign in to comment