You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
144 lines
4.2 KiB
144 lines
4.2 KiB
// Fancy widget initializations ------------------------
|
|
|
|
|
|
$(function() {
|
|
//$('.-select2').select2({
|
|
// language: 'ru',
|
|
//})
|
|
|
|
|
|
$('.-select2').select2({
|
|
ajax: {
|
|
url: "/api/specializations/",
|
|
dataType: 'json',
|
|
delay: 250,
|
|
|
|
data: function(params) {
|
|
return {
|
|
'name__icontains': params.term,
|
|
page: params.page,
|
|
}
|
|
},
|
|
|
|
processResults: function(data, params) {
|
|
params.page = params.page || 1
|
|
|
|
return {
|
|
results: _.map(function(item) {
|
|
return {
|
|
text: item.name,
|
|
id: item.id,
|
|
}
|
|
}, data.results),
|
|
|
|
pagination: {
|
|
more: (params.page * 10) < data.count
|
|
},
|
|
}
|
|
},
|
|
|
|
//cache: true
|
|
},
|
|
|
|
//escapeMarkup: function(markup) {return markup}, // let our custom formatter work
|
|
minimumInputLength: 1,
|
|
//templateResult: formatRepo, // omitted for brevity, see the source of this page
|
|
//templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
|
|
})
|
|
})
|
|
|
|
|
|
// Utils -----------------------------------------------
|
|
|
|
|
|
function humanFileSize(bytes, si) {
|
|
var thresh = si ? 1000 : 1024
|
|
|
|
if (Math.abs(bytes) < thresh)
|
|
return bytes + ' B'
|
|
|
|
var units = si
|
|
? ['kB','MB','GB','TB','PB','EB','ZB','YB']
|
|
: ['KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB']
|
|
|
|
var u = -1
|
|
|
|
do {
|
|
bytes /= thresh
|
|
++u
|
|
} while (Math.abs(bytes) >= thresh && u < units.length-1)
|
|
|
|
return bytes.toFixed(1) + ' ' + units[u]
|
|
}
|
|
|
|
|
|
//---------------------------------------------------
|
|
|
|
|
|
$('#realtyId').on('change', function($evt) {
|
|
var realtyId = Number($(this).val())
|
|
|
|
if (realtyId) {
|
|
loadRealtyDetails(realtyId).then(function(res) {
|
|
$('#realtyName').val(res.name)
|
|
$('#realtyBuildingClassificationId').val(res.building_classification.id).change()
|
|
$('#realtyConstructionTypeId').val(res.construction_type.id).change()
|
|
$('#realtyLocationId').val(res.location.id).change()
|
|
})
|
|
} else {
|
|
$('#realtyName').val('')
|
|
$('#realtyBuildingClassificationId').val('').change()
|
|
$('#realtyConstructionTypeId').val('').change()
|
|
$('#realtyLocationId').val('').change()
|
|
}
|
|
})
|
|
|
|
function loadRealtyDetails(realtyId) {
|
|
return $.ajax({
|
|
url: '/api/realties/' + realtyId + '/',
|
|
method: 'GET',
|
|
dataType: 'json',
|
|
})
|
|
.then(function(res) {return res})
|
|
.fail(function() {console.error('Failed', arguments)})
|
|
}
|
|
|
|
|
|
//---------------------------------------
|
|
|
|
|
|
var $fileUploadContainer = $('#fileUploadContainer')
|
|
|
|
$('#fileUploadAddBtn').on('click', function($evt) {
|
|
$fileUploadContainer.find('.file-upload-widget').last().children('.file-upload-input').click()
|
|
})
|
|
|
|
$fileUploadContainer.on('change', '.file-upload-input', function($evt) {
|
|
var $fileInput = $(this)
|
|
var $fileUploadWidget = $fileInput.parent('.file-upload-widget')
|
|
var filePath = $fileInput.val().replace(/\\/g, '/')
|
|
var fileName = path.basename(filePath)
|
|
//var fileExt = path.extname(filePath)
|
|
var fileSize = $fileInput.get(0).files && humanFileSize($fileInput.get(0).files[0].size)
|
|
|
|
if (fileName) {
|
|
$fileUploadWidget.children('.file-upload-label').text(fileName + ' ' + fileSize)
|
|
|
|
var $newFileUploadWidget = $fileUploadWidget.clone()
|
|
$newFileUploadWidget.children('.file-upload-label').text('')
|
|
|
|
$fileUploadContainer.children('ul').first().append($newFileUploadWidget)
|
|
|
|
$fileUploadWidget.css('display', 'block')
|
|
}
|
|
})
|
|
|
|
$fileUploadContainer.on('click', '.file-upload-remove-btn', function($evt) {
|
|
var $btn = $(this)
|
|
$btn.parent('.file-upload-widget').remove()
|
|
})
|
|
|
|
$fileUploadContainer.on('click', '.existing-file-remove-btn', function($evt) {
|
|
var $btn = $(this)
|
|
$btn.parent('.existing-file-widget').remove()
|
|
})
|
|
|