Commit 97277697 by Kálmán Viktor

network: create record button from domain edit

parent 44798159
...@@ -20,3 +20,10 @@ function getCookie(name) { ...@@ -20,3 +20,10 @@ function getCookie(name) {
} }
return cookieValue; return cookieValue;
} }
function getURLParameter(name) {
return decodeURI(
(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
);
}
...@@ -255,6 +255,41 @@ function resetName() { ...@@ -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 // on page load
// if we are upadting // if we are upadting
// - set the name and address // - set the name and address
...@@ -268,6 +303,10 @@ $(function() { ...@@ -268,6 +303,10 @@ $(function() {
} }
// else we are creaing a new // else we are creaing a new
else { else {
domain = getURLParameter('domain');
if(domain != 'null' && domain.length > 0) {
new_record = false;
} else {
new_record = true; new_record = true;
// hide all input containers // hide all input containers
$('div[id^="div_id_"]').hide(); $('div[id^="div_id_"]').hide();
...@@ -284,6 +323,7 @@ $(function() { ...@@ -284,6 +323,7 @@ $(function() {
); );
$('#div_id_type').fadeIn(); $('#div_id_type').fadeIn();
} }
}
}); });
// if the user choose a type // if the user choose a type
...@@ -303,38 +343,3 @@ function type_next() { ...@@ -303,38 +343,3 @@ function type_next() {
} }
return false; 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 @@ ...@@ -16,10 +16,10 @@
{% crispy form %} {% crispy form %}
</div> </div>
<div class="col-sm-6 col-sm-offset-1"> <div class="col-sm-6 col-sm-offset-1">
<h3> <div class="page-header">
{% trans "List of this domain's records" %} <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> <h3>{% trans "List of this domain's records" %}</h3>
<hr /> </div>
<div class="table-responsive"> <div class="table-responsive">
{% render_table record_list %} {% render_table record_list %}
</div> </div>
......
...@@ -459,6 +459,12 @@ class RecordCreate(CreateView, SuccessMessageMixin): ...@@ -459,6 +459,12 @@ class RecordCreate(CreateView, SuccessMessageMixin):
# TODO fqdn # TODO fqdn
success_message = _(u'Successfully created record!') success_message = _(u'Successfully created record!')
def get_initial(self):
return {
# 'owner': 1,
'domain': self.request.GET.get('domain'),
}
class RecordDelete(DeleteView): class RecordDelete(DeleteView):
model = Record 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