Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
tabuna committed Mar 1, 2018
2 parents 23b227a + 2632ebf commit 9af104c
Show file tree
Hide file tree
Showing 18 changed files with 646 additions and 187 deletions.
368 changes: 184 additions & 184 deletions resources/assets/js/components/attachment.js
Original file line number Diff line number Diff line change
@@ -1,189 +1,189 @@
document.addEventListener('turbolinks:load', function() {
if (document.getElementById('post-attachment-dropzone') === null) {
return;
}

const attachmentDescription = new Vue({
el: '#modalAttachment',
data: {
attachment: {},
active: null,
},
methods: {
loadInfo: function(data) {
let name = data.name + data.id;

data.url = '/storage/' + data.path + data.name + '.' + data.extension;

if (!this.attachment.hasOwnProperty(name)) {
this.attachment[name] = data;
}
this.active = name;
},
save: function() {
let data = this.attachment[this.active];

$('#modalAttachment').modal('toggle');

$.ajax({
type: 'POST',
url: dashboard.prefix('/systems/files/post/' + data.id),
data: {
_token: $("meta[name='csrf_token']").attr('content'),
attachment: data,
_method: 'PUT',
},
dataType: 'html',
success: function(data) {
console.log('file update');
},
});
},
},
});

const postDropzone = new Dropzone('.dropzone', {
url: dashboard.prefix('/systems/files'),
method: 'post',
uploadMultiple: false,
parallelUploads: 100,
maxFilesize: 9999,
paramName: 'files',
acceptedFiles: $('#post-attachment-dropzone').data('accepted'),
maxThumbnailFilesize: 99999,
previewsContainer: '.visual-dropzone',
//previewTemplate: document.getElementById('preview-template').innerHTML,
addRemoveLinks: false,
dictFileTooBig: 'File is big',

init: function() {
this.on('addedfile', function(e) {
var n = Dropzone.createElement(
"<a href='javascript:;'' class='btn-remove'><i class='fa fa-times' aria-hidden='true'></i></a>",
),
t = this;
n.addEventListener('click', function(n) {
n.preventDefault(), n.stopPropagation(), t.removeFile(e);
}),
e.previewElement.appendChild(n);

var n = Dropzone.createElement(
"<a href='javascript:;'' class='btn-edit'><i class='icon-note' aria-hidden='true'></i></a>",
),
t = this;
n.addEventListener('click', function(n) {
attachmentDescription.loadInfo(e.data);
$('#modalAttachment').modal('show');
}),
e.previewElement.appendChild(n);
});

this.on('completemultiple', function(file, json) {
$('.sortable-dropzone').sortable('enable');
});

const instanceDropZone = this;

const id = $('#post').data('post-id');
if (id !== undefined) {
$.ajax({
type: 'get',
url: dashboard.prefix('/systems/files/post/' + id),
data: { _token: $("meta[name='csrf_token']").attr('content') },
dataType: 'html',
success: function(data) {
const images = JSON.parse(data);

images.forEach(function(item, i, arr) {
const mockFile = {
id: item.id,
name: item.original_name,
size: item.size,
type: item.mime,
status: Dropzone.ADDED,
url: '/storage/' + item.path + item.name + '.' + item.extension,
data: item,
};

instanceDropZone.emit('addedfile', mockFile);
instanceDropZone.emit('thumbnail', mockFile, mockFile.url);
instanceDropZone.files.push(mockFile);
$('.dz-preview:last-child')
.attr('data-file-id', item.id)
.addClass('file-sort');
});

$('.dz-progress').remove();
},
});
}

this.on('sending', function(file, xhr, formData) {
formData.append('_token', $("meta[name='csrf_token']").attr('content'));
formData.append(
'storage',
$('#post-attachment-dropzone').data('storage'),
);
});

this.on('removedfile', function(file) {
$('.files-' + file.data.id).remove();

$.ajax({
type: 'delete',
url: dashboard.prefix('/systems/files/' + file.data.id),
data: {
_token: $("meta[name='csrf_token']").attr('content'),
storage: $('#post-attachment-dropzone').data('storage'),
},
dataType: 'html',
success: function(data) {
//
},
});
});
},
error: function(file, response) {
if ($.type(response) === 'string') {
return response; //dropzone sends it's own error messages in string
}
return response.message;
},
success: function(file, response) {
file.data = response;
$('.dz-preview:last-child')
.attr('data-file-id', response.id)
if (document.getElementById('post-attachment-dropzone') === null) {
return;
}

const attachmentDescription = new Vue({
el: '#modalAttachment',
data: {
attachment: {},
active: null,
},
methods: {
loadInfo: function(data) {
let name = data.name + data.id;

data.url = '/storage/' + data.path + data.name + '.' + data.extension;

if (!this.attachment.hasOwnProperty(name)) {
this.attachment[name] = data;
}
this.active = name;
},
save: function() {
let data = this.attachment[this.active];

$('#modalAttachment').modal('toggle');

$.ajax({
type: 'POST',
url: dashboard.prefix('/systems/files/post/' + data.id),
data: {
_token: $("meta[name='csrf_token']").attr('content'),
attachment: data,
_method: 'PUT',
},
dataType: 'html',
success: function(data) {
console.log('file update');
},
});
},
},
});

const postDropzone = new Dropzone('.dropzone', {
url: dashboard.prefix('/systems/files'),
method: 'post',
uploadMultiple: false,
parallelUploads: 100,
maxFilesize: 9999,
paramName: 'files',
acceptedFiles: $('#post-attachment-dropzone').data('accepted'),
maxThumbnailFilesize: 99999,
previewsContainer: '.visual-dropzone',
//previewTemplate: document.getElementById('preview-template').innerHTML,
addRemoveLinks: false,
dictFileTooBig: 'File is big',

init: function() {
this.on('addedfile', function(e) {
var n = Dropzone.createElement(
"<a href='javascript:;'' class='btn-remove'><i class='fa fa-times' aria-hidden='true'></i></a>",
),
t = this;
n.addEventListener('click', function(n) {
n.preventDefault(), n.stopPropagation(), t.removeFile(e);
}),
e.previewElement.appendChild(n);

var n = Dropzone.createElement(
"<a href='javascript:;'' class='btn-edit'><i class='icon-note' aria-hidden='true'></i></a>",
),
t = this;
n.addEventListener('click', function(n) {
attachmentDescription.loadInfo(e.data);
$('#modalAttachment').modal('show');
}),
e.previewElement.appendChild(n);
});

this.on('completemultiple', function(file, json) {
$('.sortable-dropzone').sortable('enable');
});

const instanceDropZone = this;

const id = $('#post').data('post-id');
if (id !== undefined) {
$.ajax({
type: 'get',
url: dashboard.prefix('/systems/files/post/' + id),
data: { _token: $("meta[name='csrf_token']").attr('content') },
dataType: 'html',
success: function(data) {
const images = JSON.parse(data);

images.forEach(function(item, i, arr) {
const mockFile = {
id: item.id,
name: item.original_name,
size: item.size,
type: item.mime,
status: Dropzone.ADDED,
url: '/storage/' + item.path + item.name + '.' + item.extension,
data: item,
};

instanceDropZone.emit('addedfile', mockFile);
instanceDropZone.emit('thumbnail', mockFile, mockFile.url);
instanceDropZone.files.push(mockFile);
$('.dz-preview:last-child')
.attr('data-file-id', item.id)
.addClass('file-sort');
$(
"<input type='hidden' class='files-" +
response.id +
"' name='files[]' value='" +
response.id +
"' />",
).appendTo('.dropzone');
},
});

$('.sortable-dropzone').sortable({
update: function() {
const items = {};
$('.file-sort').each(function(index, value) {
const id = $(this).attr('data-file-id');
items[id] = index;
});

$.ajax({
type: 'post',
url: dashboard.prefix('/systems/files/sort'),
data: {
_token: $("meta[name='csrf_token']").attr('content'),
files: items,
},
dataType: 'html',
success: function(response) {
console.log(response);
},
});
$('.dz-progress').remove();
},
});
}

this.on('sending', function(file, xhr, formData) {
formData.append('_token', $("meta[name='csrf_token']").attr('content'));
formData.append(
'storage',
$('#post-attachment-dropzone').data('storage'),
);
});

this.on('removedfile', function(file) {
$('.files-' + file.data.id).remove();

$.ajax({
type: 'delete',
url: dashboard.prefix('/systems/files/' + file.data.id),
data: {
_token: $("meta[name='csrf_token']").attr('content'),
storage: $('#post-attachment-dropzone').data('storage'),
},
dataType: 'html',
success: function(data) {
//
},
});
});
},
error: function(file, response) {
if ($.type(response) === 'string') {
return response; //dropzone sends it's own error messages in string
}
return response.message;
},
success: function(file, response) {
file.data = response;
$('.dz-preview:last-child')
.attr('data-file-id', response.id)
.addClass('file-sort');
$(
"<input type='hidden' class='files-" +
response.id +
"' name='files[]' value='" +
response.id +
"' />",
).appendTo('.dropzone');
},
});

$('.sortable-dropzone').sortable({
update: function() {
const items = {};
$('.file-sort').each(function(index, value) {
const id = $(this).attr('data-file-id');
items[id] = index;
});

$.ajax({
type: 'post',
url: dashboard.prefix('/systems/files/sort'),
data: {
_token: $("meta[name='csrf_token']").attr('content'),
files: items,
},
dataType: 'html',
success: function(response) {
console.log(response);
},
});
});
});
},
});
});
2 changes: 1 addition & 1 deletion resources/lang/ru/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
'alert' => [
'success' => 'Операция выполнена успешно.',
'restore' => 'Восстановить запись.',
'validate' => 'Пожалуйста проверьте введённые данные, возможно необходимо указать на других языках.',
'validate' => 'Пожалуйста, проверьте введённые данные, возможно необходимо указать на других языках.',
],

'filters' => [
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/ru/systems/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
'view' => 'Очистить отображаемые файлы',
'view.description' => 'Очистить все скомпилированные файлы просмотра',
'opcache' => 'Очистить opcache',
'opcache.description' => 'Сбрасывает содержимое кэша операций операций',
'opcache.description' => 'Сбрасывает содержимое кэша операций',

];
Loading

0 comments on commit 9af104c

Please sign in to comment.