2015-10-08 18:49:18 -04:00
|
|
|
<template>
|
|
|
|
<div id="image-manager">
|
2015-11-09 14:20:44 -05:00
|
|
|
<div class="overlay" v-el:overlay @click="overlayClick">
|
2015-10-08 18:49:18 -04:00
|
|
|
<div class="image-manager-body">
|
|
|
|
<div class="image-manager-content">
|
|
|
|
<div class="image-manager-list">
|
2015-11-01 15:00:57 -05:00
|
|
|
<div v-for="image in images">
|
2015-10-08 18:49:18 -04:00
|
|
|
<img class="anim fadeIn"
|
2015-11-01 15:00:57 -05:00
|
|
|
:class="{selected: (image==selectedImage)}"
|
2015-12-07 18:00:34 -05:00
|
|
|
:src="image.thumbs.gallery" :alt="image.title" :title="image.name"
|
2015-11-09 14:20:44 -05:00
|
|
|
@click="imageClick(image)"
|
|
|
|
:style="{animationDelay: ($index > 26) ? '160ms' : ($index * 25) + 'ms'}">
|
2015-10-08 18:49:18 -04:00
|
|
|
</div>
|
2015-11-09 14:20:44 -05:00
|
|
|
<div class="load-more" v-show="hasMore" @click="fetchData">Load More</div>
|
2015-10-08 18:49:18 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
2015-11-09 14:20:44 -05:00
|
|
|
<button class="neg button image-manager-close" @click="hide">x</button>
|
2015-10-08 18:49:18 -04:00
|
|
|
<div class="image-manager-sidebar">
|
2015-11-01 15:00:57 -05:00
|
|
|
<h2 v-el:image-title>Images</h2>
|
2015-10-08 18:49:18 -04:00
|
|
|
<hr class="even">
|
2015-11-01 15:00:57 -05:00
|
|
|
<div class="dropzone-container" v-el:drop-zone>
|
2015-10-08 18:49:18 -04:00
|
|
|
<div class="dz-message">Drop files or click here to upload</div>
|
|
|
|
</div>
|
|
|
|
<div class="image-manager-details anim fadeIn" v-show="selectedImage">
|
|
|
|
<hr class="even">
|
2015-11-09 14:20:44 -05:00
|
|
|
<form @submit="saveImageDetails" v-el:image-form>
|
2015-10-08 18:49:18 -04:00
|
|
|
<div class="form-group">
|
|
|
|
<label for="name">Image Name</label>
|
|
|
|
<input type="text" id="name" name="name" v-model="selectedImage.name">
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
<hr class="even">
|
|
|
|
<div v-show="dependantPages">
|
|
|
|
<p class="text-neg text-small">
|
2015-10-18 13:48:51 -04:00
|
|
|
This image is used in the pages below, Click delete again to confirm you want to delete
|
|
|
|
this image.
|
2015-10-08 18:49:18 -04:00
|
|
|
</p>
|
|
|
|
<ul class="text-neg">
|
2015-11-01 15:00:57 -05:00
|
|
|
<li v-for="page in dependantPages">
|
|
|
|
<a :href="page.url" target="_blank" class="text-neg">{{ page.name }}</a>
|
2015-10-08 18:49:18 -04:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
|
2015-11-09 14:20:44 -05:00
|
|
|
<form @submit="deleteImage" v-el:image-delete-form>
|
2015-10-08 18:49:18 -04:00
|
|
|
<button class="button neg"><i class="zmdi zmdi-delete"></i>Delete Image</button>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
<div class="image-manager-bottom">
|
2015-11-09 14:20:44 -05:00
|
|
|
<button class="button pos anim fadeIn" v-show="selectedImage" @click="selectButtonClick"><i
|
2015-10-18 13:48:51 -04:00
|
|
|
class="zmdi zmdi-square-right"></i>Select Image
|
|
|
|
</button>
|
2015-10-08 18:49:18 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
var Dropzone = require('dropzone');
|
|
|
|
|
|
|
|
module.exports = {
|
2015-10-18 13:48:51 -04:00
|
|
|
data: function () {
|
2015-10-08 18:49:18 -04:00
|
|
|
return {
|
|
|
|
images: [],
|
|
|
|
hasMore: false,
|
|
|
|
page: 0,
|
|
|
|
cClickTime: 0,
|
|
|
|
selectedImage: false,
|
|
|
|
dependantPages: false,
|
|
|
|
deleteForm: {},
|
2015-10-18 13:48:51 -04:00
|
|
|
token: document.querySelector('meta[name=token]').getAttribute('content'),
|
|
|
|
dataLoaded: false
|
2015-10-08 18:49:18 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-12-08 17:04:59 -05:00
|
|
|
props: {
|
|
|
|
imageType: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-10-08 18:49:18 -04:00
|
|
|
created: function () {
|
|
|
|
window.ImageManager = this;
|
|
|
|
},
|
|
|
|
|
|
|
|
ready: function () {
|
|
|
|
// Create dropzone
|
|
|
|
this.setupDropZone();
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
fetchData: function () {
|
2015-12-28 10:58:13 -05:00
|
|
|
var url = '/images/' + this.imageType + '/all/' + this.page;
|
|
|
|
this.$http.get(url).then((response) => {
|
|
|
|
this.images = this.images.concat(response.data.images);
|
|
|
|
this.hasMore = response.data.hasMore;
|
|
|
|
this.page++;
|
2015-10-08 18:49:18 -04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
setupDropZone: function () {
|
|
|
|
var _this = this;
|
2015-11-01 15:00:57 -05:00
|
|
|
var dropZone = new Dropzone(_this.$els.dropZone, {
|
2015-12-08 17:04:59 -05:00
|
|
|
url: '/images/' + _this.imageType + '/upload',
|
2015-10-08 18:49:18 -04:00
|
|
|
init: function () {
|
|
|
|
var dz = this;
|
2015-12-28 10:58:13 -05:00
|
|
|
dz.on("sending", function (file, xhr, data) {
|
2015-10-08 18:49:18 -04:00
|
|
|
data.append("_token", _this.token);
|
|
|
|
});
|
2015-12-28 10:58:13 -05:00
|
|
|
dz.on("success", function (file, data) {
|
2015-10-08 18:49:18 -04:00
|
|
|
_this.images.unshift(data);
|
|
|
|
$(file.previewElement).fadeOut(400, function () {
|
|
|
|
dz.removeFile(file);
|
|
|
|
});
|
|
|
|
});
|
2015-12-28 10:58:13 -05:00
|
|
|
dz.on('error', function (file, errorMessage, xhr) {
|
2015-12-07 18:00:34 -05:00
|
|
|
if (errorMessage.file) {
|
2015-12-01 15:26:09 -05:00
|
|
|
$(file.previewElement).find('[data-dz-errormessage]').text(errorMessage.file[0]);
|
|
|
|
}
|
|
|
|
console.log(errorMessage);
|
|
|
|
});
|
2015-10-08 18:49:18 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-12-08 17:04:59 -05:00
|
|
|
returnCallback: function (image) {
|
2015-12-09 17:30:55 -05:00
|
|
|
this.callback(image);
|
2015-12-08 17:04:59 -05:00
|
|
|
},
|
|
|
|
|
2015-10-08 18:49:18 -04:00
|
|
|
imageClick: function (image) {
|
|
|
|
var dblClickTime = 380;
|
|
|
|
var cTime = (new Date()).getTime();
|
|
|
|
var timeDiff = cTime - this.cClickTime;
|
|
|
|
if (this.cClickTime !== 0 && timeDiff < dblClickTime && this.selectedImage === image) {
|
|
|
|
// DoubleClick
|
|
|
|
if (this.callback) {
|
2015-12-08 17:04:59 -05:00
|
|
|
this.returnCallback(image);
|
2015-10-08 18:49:18 -04:00
|
|
|
}
|
|
|
|
this.hide();
|
|
|
|
} else {
|
|
|
|
this.selectedImage = (this.selectedImage === image) ? false : image;
|
|
|
|
this.dependantPages = false;
|
|
|
|
}
|
|
|
|
this.cClickTime = cTime;
|
|
|
|
},
|
|
|
|
|
|
|
|
selectButtonClick: function () {
|
2015-12-28 10:58:13 -05:00
|
|
|
if (this.callback) this.returnCallback(this.selectedImage);
|
2015-10-08 18:49:18 -04:00
|
|
|
this.hide();
|
|
|
|
},
|
|
|
|
|
|
|
|
show: function (callback) {
|
|
|
|
this.callback = callback;
|
2015-11-01 15:00:57 -05:00
|
|
|
this.$els.overlay.style.display = 'block';
|
2015-10-18 13:48:51 -04:00
|
|
|
// Get initial images if they have not yet been loaded in.
|
|
|
|
if (!this.dataLoaded) {
|
|
|
|
this.fetchData(this.page);
|
|
|
|
this.dataLoaded = true;
|
|
|
|
}
|
2015-10-08 18:49:18 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
overlayClick: function (e) {
|
|
|
|
if (e.target.className === 'overlay') {
|
|
|
|
this.hide();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
hide: function () {
|
2015-11-01 15:00:57 -05:00
|
|
|
this.$els.overlay.style.display = 'none';
|
2015-10-08 18:49:18 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
saveImageDetails: function (e) {
|
|
|
|
e.preventDefault();
|
2015-12-28 10:58:13 -05:00
|
|
|
this.selectedImage._token = this.token;
|
|
|
|
var form = $(this.$els.imageForm);
|
|
|
|
var url = '/images/update/' + this.selectedImage.id;
|
|
|
|
this.$http.put(url, this.selectedImage).then((response) => {
|
2015-10-08 18:49:18 -04:00
|
|
|
form.showSuccess('Image name updated');
|
2015-12-28 10:58:13 -05:00
|
|
|
}, (response) => {
|
|
|
|
form.showFailure(response.data);
|
|
|
|
});
|
2015-10-08 18:49:18 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
deleteImage: function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
var _this = this;
|
|
|
|
_this.deleteForm.force = _this.dependantPages !== false;
|
|
|
|
_this.deleteForm._token = _this.token;
|
2015-12-28 10:58:13 -05:00
|
|
|
var url = '/images/' + _this.selectedImage.id;
|
|
|
|
this.$http.delete(url, this.deleteForm).then((response) => {
|
|
|
|
this.images.splice(this.images.indexOf(this.selectedImage), 1);
|
|
|
|
this.selectedImage = false;
|
|
|
|
$(this.$els.imageTitle).showSuccess('Image Deleted');
|
|
|
|
}, (response) => {
|
2015-10-08 18:49:18 -04:00
|
|
|
// Pages failure
|
2015-12-28 10:58:13 -05:00
|
|
|
if (response.status === 400) {
|
|
|
|
_this.dependantPages = response.data;
|
2015-10-08 18:49:18 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
</script>
|