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.
 
 
 
 
 
 

120 lines
3.4 KiB

/**
* Created by dev on 07.09.2015.
*/
$(document).ready(function () {
$('select').select2({
width: 'element',
allowClear: true
});
$('#id_country').change(function () {
$.get(
"/admin/ajax_city/", {'id': $(this).val()}, function (j) {
$('#id_city').html(j);
$('#id_city').attr('disabled', false);
});
});
$('#id_city').select2({
placeholder: "Город",
width: 300,
ajax: {
url: "/admin/city/search/",
dataType: "json",
quietMillis: 200,
data: function (term, page, country) {
var country = $('#id_country').val();
return {
term: term,
page: page,
country: country
};
},
results: function (data) {
var results = [];
$.each(data, function (index, item) {
results.push({
id: item.id,
text: item.label
});
});
return {results: results};
}
},
initSelection: function (element, callback) {
var id = $(element).val();
var text = $(element).attr('data-init-text');
callback({id: id, text: text});
}
});
// displaying uploaded photo
function handleFileSelect1(evt) {
var files = evt.target.files; // FileList object
// Loop through the FileList and render image files as thumbnails.
for (var i = 0, f; f = files[i]; i++) {
// Only process image files.
if (!f.type.match('image.*')) {
continue;
}
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = (function (theFile) {
return function (e) {
document.getElementById('list_picture').innerHTML = ['<img class="thumb" src="',
e.target.result, '" title="', escape(theFile.name), '"/>'].join('');
};
})(f);
// Read in the image file as a data URL.
reader.readAsDataURL(f);
}
}
function handleFileSelect2(evt) {
var files = evt.target.files; // FileList object
// Loop through the FileList and render image files as thumbnails.
for (var i = 0, f; f = files[i]; i++) {
// Only process image files.
if (!f.type.match('image.*')) {
continue;
}
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = (function (theFile) {
return function (e) {
document.getElementById('list_logo').innerHTML = ['<img class="thumb" src="',
e.target.result, '" title="', escape(theFile.name), '"/>'].join('');
};
})(f);
// Read in the image file as a data URL.
reader.readAsDataURL(f);
}
}
document.getElementById('id_place_photo').addEventListener('change', handleFileSelect1, false);
document.getElementById('id_logo_preview').addEventListener('change', handleFileSelect2, false);
console.log("hello from new catalog view.js");
});