parent
6f21ff0ade
commit
f56a319d21
10 changed files with 474 additions and 0 deletions
@ -0,0 +1,43 @@ |
||||
.inline-related { |
||||
border: 1px solid #CCC; |
||||
border-radius: 2px; |
||||
box-shadow: 0 1px 2px 1px rgba(0, 0, 0, 0.08); |
||||
} |
||||
|
||||
.inline-related h3 { |
||||
background-color: #FCFCFC; |
||||
padding: 10px 20px 10px 3px; |
||||
margin: 0; |
||||
text-align: center; |
||||
} |
||||
|
||||
.inline-related .inline_label { |
||||
font-weight: 300; |
||||
} |
||||
|
||||
|
||||
.inline-related .collapse-expand { |
||||
display: inline-block; |
||||
text-transform: uppercase; |
||||
padding: 0px 10px 0px 10px; |
||||
width: 44px; |
||||
float: left; |
||||
text-decoration:none!important; |
||||
} |
||||
|
||||
.add-row { |
||||
height: 26px; |
||||
line-height: 26px; |
||||
text-align: center; |
||||
border: 1px dashed #CCC!important; |
||||
border-radius: 2px; |
||||
margin: 0; |
||||
} |
||||
|
||||
.add-row a { |
||||
display: block; |
||||
padding-left: 14px; |
||||
text-indent: -9999px; |
||||
font-size: 11px; |
||||
background-position: 50% 50%!important; |
||||
} |
||||
@ -0,0 +1,53 @@ |
||||
(function($) { |
||||
$(function() { |
||||
var formsubmission_form = $('#formsubmission_form'); |
||||
var form_field = $('select[id="id_form"]', formsubmission_form); |
||||
var headers_field = $('.field-headers', formsubmission_form); |
||||
|
||||
var loadHeaders = function() { |
||||
if (!form_field.val()) { |
||||
headers_field.slideUp('fast'); |
||||
return; |
||||
} |
||||
|
||||
var data = { |
||||
'csrfmiddlewaretoken': $('input[name="csrfmiddlewaretoken"]').val(), |
||||
'form': $('select[name="form"]').val(), |
||||
'file_type': $('select[name="file_type"]').val() |
||||
}; |
||||
|
||||
$.ajax({ |
||||
type: 'POST', |
||||
url: '', |
||||
data: data, |
||||
success: function(response) { |
||||
if (response.reloadBrowser) { |
||||
location.reload(); |
||||
} |
||||
$('select[id="id_headers_to"]').find('option').remove(); |
||||
|
||||
var headers_input_from = $('select[id="id_headers_from"]'); |
||||
headers_input_from.find('option').remove(); |
||||
|
||||
$.each(response.availableHeaders, function(index, value) { |
||||
headers_input_from.append('<option value=' + value + '>' + value + '</option>'); |
||||
}); |
||||
|
||||
SelectBox.init('id_headers_from'); |
||||
SelectBox.init('id_headers_to'); |
||||
headers_field.slideDown(); |
||||
}, |
||||
error: function() { |
||||
alert('We\'re sorry. Something unexpected happened. Please reload the page and try again.'); |
||||
} |
||||
}); |
||||
|
||||
return false; |
||||
}; |
||||
|
||||
if ($('body').hasClass('export-form')) { |
||||
loadHeaders(); |
||||
form_field.change(loadHeaders); |
||||
} |
||||
}); |
||||
})(django.jQuery); |
||||
@ -0,0 +1,66 @@ |
||||
/* |
||||
Makes all inline forms collapsible. |
||||
*/ |
||||
|
||||
jQuery(function($) { |
||||
$.makeCollapsible = function(target, item, collapsible, triggerTarget, setInitStatus, setFirstStatus) |
||||
{ |
||||
var triggerExpand = 'Edit'; |
||||
var triggerCollapse = 'Done'; |
||||
var triggerClass = 'collapse-expand'; |
||||
var triggerLink = '<a class="' + triggerClass + '" href="javascript:void(0);"></a>'; |
||||
|
||||
$(target).find(item).each(function(i) { |
||||
if ($(this).data('isCollapsible')) return; |
||||
$(this).data('isCollapsible', true); |
||||
|
||||
$(this).find(collapsible).hide(); |
||||
|
||||
// trigger already exists if created with "Add another" link
|
||||
var trigger = $(this).find(triggerTarget).find('.'+triggerClass); |
||||
if (!trigger.length) { |
||||
trigger = $(triggerLink); |
||||
$(this).find(triggerTarget).html(trigger); |
||||
} |
||||
|
||||
var item = this; |
||||
var toggleCollapse = function(status, speed) |
||||
{ |
||||
if (status == null) { |
||||
status = !item.collapseStatus; |
||||
} |
||||
if (speed == null) { |
||||
speed = 1; |
||||
} |
||||
item.collapseStatus = status; |
||||
if (status) { |
||||
trigger.html(triggerCollapse); |
||||
$(item).find(collapsible).slideDown('slow'); |
||||
} else { |
||||
trigger.html(triggerExpand); |
||||
$(item).find(collapsible).slideUp('slow'); |
||||
} |
||||
} |
||||
|
||||
trigger.click(function(event) { |
||||
event.preventDefault(); |
||||
toggleCollapse(null, 'normal') |
||||
}) |
||||
|
||||
// Collapse by default unless there are errors
|
||||
initStatus = setInitStatus != null ? setInitStatus : $(this).find('.errors').length != 0; |
||||
firstStatus = setFirstStatus != null ? setFirstStatus : initStatus; |
||||
|
||||
toggleCollapse(i == 0 ? firstStatus : initStatus) |
||||
}); |
||||
}; |
||||
|
||||
var init = function() { |
||||
$.makeCollapsible('div.inline-group', 'div.inline-related', 'fieldset', 'h3 b'); |
||||
}; |
||||
init(); |
||||
// init again when "Add another" link is clicked
|
||||
$('.add-row a').click(function() { |
||||
init(); |
||||
}) |
||||
}); |
||||
@ -0,0 +1,95 @@ |
||||
/* |
||||
Enables repositioning of all inline elements by drag & drop. |
||||
|
||||
The inline model requires is a "position" field that is blank by default. |
||||
This value will be set automatically by this code snippet when dragging elements. |
||||
The model instances can then be ordered by that "position" field. |
||||
*/ |
||||
|
||||
jQuery(function($) { |
||||
|
||||
var positionField = 'position'; |
||||
var target = $('div.inline-group#fields-group'); |
||||
var handle = 'h3'; |
||||
var item = 'div.inline-related'; |
||||
var positionInput = 'input[id$=-'+positionField+']'; |
||||
var hidePositionFieldClosest = '.form-row'; |
||||
|
||||
var renumberAll = function() { |
||||
var pos = 1; |
||||
target.find(item).each(function(i) { |
||||
$(this).removeClass('odd even').addClass(i % 2 ? 'even' : 'odd'); |
||||
if ($(this).find(positionInput).val() != '') { |
||||
$(this).find(positionInput).val(pos); |
||||
pos++; |
||||
} |
||||
}); |
||||
}; |
||||
|
||||
var init = function() { |
||||
target.find(item).each(function(i) { |
||||
if ($(this).data('isSortable')) return; |
||||
$(this).data('isSortable', true); |
||||
$(this).find(handle).css('cursor', 'ns-resize'); |
||||
$(this).find(handle).addClass('draggable'); |
||||
$(this).find(positionInput).each(function() { |
||||
if (hidePositionFieldClosest) { |
||||
var hidden =$('<input type="hidden" id="'+this.id+'" name="'+this.name+'" />'); |
||||
hidden.val($(this).val()); |
||||
$(this).closest(hidePositionFieldClosest).replaceWith(hidden); |
||||
} |
||||
}); |
||||
$(this).find('input, select, textarea').change(function() { |
||||
$(this).closest(item).find('input[id$='+positionField+']').val('X'); // mark for renumberAll() to fill in
|
||||
renumberAll($('div.inline-group')); |
||||
}); |
||||
}); |
||||
}; |
||||
|
||||
var addRow = target.find('.add-row'); |
||||
addRow.remove(); |
||||
var ordered = []; |
||||
var unordered = []; |
||||
// Initially, remove and re-append all inlines ordered by their "position" value
|
||||
target.find(item).each(function(i) { |
||||
var initialPos = $(this).find(positionInput).val(); |
||||
if (initialPos) { |
||||
while (initialPos < ordered.length && ordered[initialPos]) { |
||||
initialPos++; |
||||
} |
||||
ordered[initialPos] = this; |
||||
} else { |
||||
unordered[unordered.length] = this; |
||||
} |
||||
$(this).removeClass('odd even').addClass(i % 2 ? 'even' : 'odd'); |
||||
this.parentElement.removeChild(this); |
||||
}); |
||||
for (var i = 0; i < ordered.length; i++) { |
||||
var el = ordered[i]; |
||||
if (el) { |
||||
target.append(el); |
||||
} |
||||
} |
||||
// Add "position"-less elements in the end
|
||||
for (var i = 0; i < unordered.length; i++) { |
||||
var el = unordered[i]; |
||||
target.append(el); |
||||
} |
||||
target.append(addRow); |
||||
|
||||
target.sortable({ |
||||
containment: 'parent', |
||||
items: item, |
||||
handle: handle, |
||||
update: renumberAll, |
||||
revert: true, |
||||
opacity: 0.9 |
||||
}); |
||||
|
||||
init(); |
||||
// init again when "Add another" link is clicked
|
||||
$('.add-row a').click(function() { |
||||
init(); |
||||
}); |
||||
|
||||
}); |
||||
@ -0,0 +1,45 @@ |
||||
/* |
||||
Replaces the name in an inline element's header while typing it in the input of the "name" field. |
||||
This way, the extra inline element's header will be named instead of numbered #4, #5 etc. |
||||
*/ |
||||
|
||||
jQuery(function($) { |
||||
|
||||
var target = $('div.inline-group'); |
||||
var item = 'div.inline-related'; |
||||
var nameInput = 'input[id*=-label]'; |
||||
var typeInput = 'select[id*=-field_type]'; |
||||
|
||||
|
||||
var init = function() { |
||||
target.find(item).each(function() { |
||||
var nameField = $(this).find(nameInput); |
||||
var typeField = $(this).find(typeInput); |
||||
var label = $('.inline_label', this); |
||||
var rename = function() { |
||||
if (nameField.val()) { |
||||
label.text(nameField.val()); |
||||
} |
||||
else { |
||||
label.text(typeField.find('option:selected').text() + ' Field'); |
||||
} |
||||
}; |
||||
nameField.keyup(function(event) { |
||||
// Update name while typing
|
||||
rename(); |
||||
}); |
||||
|
||||
typeField.change(function(){ |
||||
rename(); |
||||
}); |
||||
rename(); |
||||
}) |
||||
} |
||||
|
||||
init(); |
||||
|
||||
// init again when "Add another" link is clicked
|
||||
$('.add-row a').click(function() { |
||||
init(); |
||||
}) |
||||
}); |
||||
@ -0,0 +1,35 @@ |
||||
jQuery(function($) { |
||||
var target = $('div.inline-group'); |
||||
var item = 'div.inline-related'; |
||||
var typeInput = 'select[id*=-field_type]'; |
||||
|
||||
var init = function() { |
||||
target.find(item).each(function() { |
||||
var that = $(this); |
||||
var inputField = that.find(typeInput); |
||||
var toggleField = function() { |
||||
var selectedFieldType = inputField.val(); |
||||
var choiceFields = ['checkbox_multiple', 'select', 'radio', 'file']; |
||||
var showChoiceField = $.inArray(selectedFieldType, choiceFields) >= 0; |
||||
that.find('.field-choice_values') |
||||
.toggle(showChoiceField) |
||||
.toggleClass('required', showChoiceField); |
||||
|
||||
that.find('.field-placeholder_text, .field-help_text, .field-choice_values:not(:hidden)') |
||||
.toggle(selectedFieldType != 'hidden') |
||||
|
||||
}; |
||||
inputField.change(function() { |
||||
toggleField(); |
||||
}); |
||||
toggleField(); |
||||
}) |
||||
}; |
||||
|
||||
init(); |
||||
|
||||
// init again when "Add another" link is clicked
|
||||
$('.add-row a').click(function() { |
||||
init(); |
||||
}) |
||||
}); |
||||
@ -0,0 +1,109 @@ |
||||
(function ($) { |
||||
$.fn.djangocms_forms = function (options) { |
||||
if (options === undefined) { options = {}; } |
||||
|
||||
var defaults = { |
||||
form_wrapper: '.form-wrapper', |
||||
field_wrapper: '.field-wrapper', |
||||
form_errors: '.form-errors', |
||||
field_errors: '.field-errors', |
||||
form_success: '.form-success', |
||||
errorlist_css_class: 'errorlist', |
||||
error_css_class: 'error', |
||||
server_error: 'We\'re sorry. Something Unexpected Happened. Please Try Again Later.' |
||||
}; |
||||
|
||||
$('input[type=tel]').inputmask("+7 999 999-99-99"); |
||||
|
||||
if(typeof consultation != "undefined") { |
||||
$('input[name=sotrudnik]').val(consultation.name); |
||||
} |
||||
|
||||
this.each(function(options) { |
||||
var options = $.extend( {}, defaults, options) ; |
||||
|
||||
var el = $(this), |
||||
form_wrapper = $(options.form_wrapper, el), |
||||
form_success = $(options.form_success, el), |
||||
form = $('form', form_wrapper); |
||||
|
||||
|
||||
function clearErrors() { |
||||
form.find(options.form_errors).fadeOut().empty(); //clear form errors
|
||||
form.find(options.field_errors).fadeOut().empty(); //clear field errors
|
||||
form.find(options.field_wrapper).removeClass(options.error_css_class); //remove error classes
|
||||
} |
||||
|
||||
// post-submit callback
|
||||
function ajaxSuccess(response) { |
||||
if (response.status == 'success'){ |
||||
formValid(response.redirect_url); |
||||
} |
||||
else if (response.status == 'error'){ |
||||
formInvalid(response.form_errors); |
||||
} |
||||
} |
||||
|
||||
function formValid(success_url) { |
||||
form_success.fadeIn('slow'); |
||||
form_wrapper.slideUp('slow').remove(); |
||||
|
||||
if (success_url){ |
||||
setTimeout(function(){ |
||||
window.location = success_url; |
||||
}, 1000); |
||||
} |
||||
|
||||
} |
||||
|
||||
function formInvalid(form_errors) { |
||||
clearErrors() |
||||
$.each(form_errors, function(key, value) { |
||||
var field = form.find(':input[name=' + key + ']').first(); |
||||
var field_wrapper = field.parents(options.field_wrapper).addClass(options.error_css_class); |
||||
var field_error = $('<ul/>').addClass(options.errorlist_css_class); |
||||
$.each(value, function(key, value) { |
||||
$('<li>', { |
||||
text: value |
||||
}).appendTo(field_error); |
||||
}); |
||||
field_wrapper.find(options.field_errors).append(field_error).fadeIn('slow') |
||||
}); |
||||
if (form_errors.__all__) { |
||||
var form_error = $('<ul/>').addClass(options.errorlist_css_class); |
||||
$.each(form_errors.__all__, function(key, value) { |
||||
$('<li>', { |
||||
text: value |
||||
}).appendTo(form_error); |
||||
}); |
||||
form.find(options.form_errors).append(form_error).fadeIn('slow'); |
||||
} |
||||
} |
||||
|
||||
function ajaxError() { |
||||
clearErrors(); |
||||
var form_error = $('<ul/>').addClass(options.error_class); |
||||
$('<li>', { |
||||
html: options.server_error |
||||
}).appendTo(form_error); |
||||
form.find(options.form_errors).append(form_error).fadeIn('slow'); |
||||
} |
||||
|
||||
// attach handler to form's submit event
|
||||
form.submit(function () { |
||||
var ajaxOptions = { |
||||
type: 'POST', |
||||
success: ajaxSuccess, |
||||
error: ajaxError |
||||
}; |
||||
// submit the form
|
||||
$(this).ajaxSubmit(ajaxOptions); |
||||
|
||||
form.find('button[type="submit"]').attr('disabled','disabled'); |
||||
|
||||
// return false to prevent normal browser submit and page navigation
|
||||
return false; |
||||
}); |
||||
}); |
||||
}; |
||||
})(jQuery); |
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue