0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00

Ember Admin - Upload Modal

Issue #2547
This commit is contained in:
Lucas Holmquist 2014-06-06 10:44:09 -04:00
parent 2bd3a77fa7
commit 833699bbb4
8 changed files with 47 additions and 25 deletions

View file

@ -1,17 +1,36 @@
/*global console */
import ModalDialog from 'ghost/components/gh-modal-dialog';
import upload from 'ghost/assets/lib/uploader';
var UploadModal = ModalDialog.extend({
layoutName: 'components/gh-modal-dialog',
didInsertElement: function () {
this._super();
var filestorage = $('#general').data('filestorage');
upload.call(this.$('.js-drop-zone'), {fileStorage: filestorage});
},
confirm: {
reject: {
func: function () { // The function called on rejection
return true;
},
buttonClass: true,
text: 'Cancel' // The reject button text
},
accept: {
buttonClass: 'button-save right',
text: 'Save', // The accept button texttext: 'Save'
func: function () {
var imageType = 'model.' + this.get('imageType');
// @TODO: get this real
console.log('UploadController:afterRender');
// var filestorage = $('#' + this.options.model.id).data('filestorage');
// this.$('.js-drop-zone').upload({fileStorage: filestorage});
if (this.$('.js-upload-url').val()) {
this.set(imageType, this.$('.js-upload-url').val());
} else {
this.set(imageType, this.$('.js-upload-target').attr('src'));
}
return true;
}
}
},
actions: {
@ -21,12 +40,11 @@ var UploadModal = ModalDialog.extend({
confirm: function (type) {
var func = this.get('confirm.' + type + '.func');
if (typeof func === 'function') {
func();
func.apply(this);
}
this.sendAction();
}
},
}
});
export default UploadModal;

View file

@ -1,5 +1,6 @@
var UploadController = Ember.Controller.extend({
acceptEncoding: 'image/*',
actions: {
confirmReject: function () {
return true;

View file

@ -3,8 +3,8 @@ var settings = {
"title": "Ghost",
"description": "Just a blogging platform.",
"email": "ghost@tryghost.org",
"logo": "",
"cover": "",
"logo": "http://media-cache-ec0.pinimg.com/236x/be/35/06/be35065e6f9a613d4a7661a6f45d0831.jpg",
"cover": "http://i906.photobucket.com/albums/ac267/df853/bring_me_a_shrubbery_cat.jpg",
"defaultLang": "en_US",
"postsPerPage": "6",
"forceI18n": "true",

View file

@ -24,12 +24,14 @@ var ApplicationRoute = Ember.Route.extend({
this.set('controller.user', null);
},
openModal: function (modalName, model) {
openModal: function (modalName, model, type) {
modalName = 'modals/' + modalName;
// We don't always require a modal to have a controller
// so we're skipping asserting if one exists
if (this.controllerFor(modalName, true)) {
this.controllerFor(modalName).set('model', model);
this.controllerFor(modalName).set('imageType', type);
this.controllerFor(modalName).set('src', model.get(type));
}
return this.render(modalName, {
into: 'application',

View file

@ -1,2 +1,4 @@
<input type="file" class="button-add" />
<button type="submit" class="button-save" {{bind-attr disabled=uploadButtonDisabled}} {{action "upload"}}>{{uploadButtonText}}</button>
<section class="js-drop-zone">
<img class="js-upload-target" {{bind-attr src=src}} alt="logo">
<input data-url="upload" class="js-fileupload main" type="file" name="uploadimage" {{#if options.acceptEncoding}}accept="{{options.acceptEncoding}}"{{/if}}>
</section>

View file

@ -1,9 +1,8 @@
{{#gh-upload-modal action="closeModal" close=true type="action" style="wide"
{{#gh-upload-modal action="closeModal" close=true type="action" style="wide" model=model imageType=imageType
animation="fade"}}
<section class="js-drop-zone">
<img class="js-upload-target" {{bind-attr src=src}} alt="logo">
<input data-url="upload" class="js-fileupload main" type="file" name="uploadimage" {{#if options.acceptEncoding}}accept="{{options.acceptEncoding}}"{{/if}}>
<input data-url="upload" class="js-fileupload main" type="file" name="uploadimage" {{bind-attr accept=acceptEncoding}} >
</section>
{{/gh-upload-modal}}

View file

@ -29,9 +29,9 @@
<div class="form-group">
<label for="blog-logo">Blog Logo</label>
{{#if logo}}
<a class="js-modal-logo" href="#" {{action "openModal" "upload"}}><img id="blog-logo" {{bind-attr src=logo}} alt="logo"></a>
<a class="js-modal-logo" href="#" {{action "openModal" "upload" this "logo"}}><img id="blog-logo" {{bind-attr src=logo}} alt="logo"></a>
{{else}}
<a class="button-add js-modal-logo" {{action "openModal" "upload"}}>Upload Image</a>
<a class="button-add js-modal-logo" {{action "openModal" "upload" this "logo"}}>Upload Image</a>
{{/if}}
<p>Display a sexy logo for your publication</p>
</div>
@ -39,9 +39,9 @@
<div class="form-group">
<label for="blog-cover">Blog Cover</label>
{{#if cover}}
<a class="js-modal-cover" href="#" {{action "openModal" "upload"}}><img id="blog-cover" {{bind-attr src=logo}} alt="cover photo"></a>
<a class="js-modal-cover" href="#" {{action "openModal" "upload" this "cover"}}><img id="blog-cover" {{bind-attr src=cover}} alt="cover photo"></a>
{{else}}
<a class="button-add js-modal-cover" {{action "openModal" "upload"}}>Upload Image</a>
<a class="button-add js-modal-cover" {{action "openModal" "upload" this "cover"}}>Upload Image</a>
{{/if}}
<p>Display a cover image on your site</p>
</div>

View file

@ -11,7 +11,7 @@
<header class="user-profile-header">
<img id="user-cover" class="cover-image" {{bind-attr src=cover title=coverTitle}} />
<a class="edit-cover-image js-modal-cover button" {{action "openModal" "upload"}}>Change Cover</a>
<a class="edit-cover-image js-modal-cover button" {{action "openModal" "upload" user "cover"}}>Change Cover</a>
</header>
<form class="user-profile" novalidate="novalidate">
@ -20,7 +20,7 @@
<figure class="user-image">
<div id="user-image" class="img" {{bind-attr style=image}} href="#"><span class="hidden">{{name}}"s Picture</span></div>
<a href="" {{action "openModal" "upload"}} class="edit-user-image js-modal-image">Edit Picture</a>
<a href="" {{action "openModal" "upload" user "image"}} class="edit-user-image js-modal-image">Edit Picture</a>
</figure>
<div class="form-group">