mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Merge pull request #655 from cobbspur/userprofile
User Profile Image Upload
This commit is contained in:
commit
846a5edbd1
4 changed files with 88 additions and 45 deletions
36
ghost/admin/models/uploadModal.js
Normal file
36
ghost/admin/models/uploadModal.js
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
/*global Ghost, Backbone */
|
||||||
|
(function () {
|
||||||
|
"use strict";
|
||||||
|
Ghost.Models.uploadModal = Backbone.Model.extend({
|
||||||
|
|
||||||
|
options: {
|
||||||
|
close: false,
|
||||||
|
type: "action",
|
||||||
|
style: "wide",
|
||||||
|
animation: 'fadeIn',
|
||||||
|
afterRender: function () {
|
||||||
|
this.$('.js-drop-zone').upload();
|
||||||
|
},
|
||||||
|
confirm: {
|
||||||
|
reject: {
|
||||||
|
func: function () { // The function called on rejection
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
buttonClass: true,
|
||||||
|
text: "Cancel" // The reject button text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
content: {
|
||||||
|
template: 'uploadImage'
|
||||||
|
},
|
||||||
|
|
||||||
|
initialize: function (options) {
|
||||||
|
this.options.id = options.id;
|
||||||
|
this.options.key = options.key;
|
||||||
|
this.options.src = options.src;
|
||||||
|
this.options.confirm.accept = options.accept;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}());
|
|
@ -1,4 +1,4 @@
|
||||||
<section class="js-drop-zone">
|
<section class="js-drop-zone">
|
||||||
<img id="{{options.val}}" class="js-upload-target" src="{{options.src}}"{{#unless options.src}} style="display: none"{{/unless}} alt="logo">
|
<img id="{{options.id}}" class="js-upload-target" src="{{options.src}}"{{#unless options.src}} style="display: none"{{/unless}} alt="logo">
|
||||||
<input data-url="upload" class="js-fileupload" type="file" name="uploadimage">
|
<input data-url="upload" class="js-fileupload" type="file" name="uploadimage">
|
||||||
</section>
|
</section>
|
||||||
|
|
|
@ -8,14 +8,14 @@
|
||||||
<header class="user-profile-header">
|
<header class="user-profile-header">
|
||||||
<figure class="cover-image">
|
<figure class="cover-image">
|
||||||
<img id="user-cover-picture" src="{{#if cover_picture}}{{cover_picture}}{{else}}/shared/img/default-user-cover-picture.jpg{{/if}}" title="{{full_name}} Cover Image"/>
|
<img id="user-cover-picture" src="{{#if cover_picture}}{{cover_picture}}{{else}}/shared/img/default-user-cover-picture.jpg{{/if}}" title="{{full_name}} Cover Image"/>
|
||||||
<button class="button-change-cover">Change Cover</button>
|
<button class="button-change-cover js-modal-cover-picture">Change Cover</button>
|
||||||
</figure>
|
</figure>
|
||||||
</header>
|
</header>
|
||||||
<form class="user-details-container" novalidate="novalidate">
|
<form class="user-details-container" novalidate="novalidate">
|
||||||
<fieldset class="user-details-top">
|
<fieldset class="user-details-top">
|
||||||
<figure class="user-avatar-image">
|
<figure class="user-avatar-image">
|
||||||
<img id="user-profile-picture" src="{{#if profile_picture}}{{profile_picture}}{{else}}/shared/img/default-user-profile-picture.jpg{{/if}}" title="{{full_name}}"/>
|
<img id="user-profile-picture" src="{{#if profile_picture}}{{profile_picture}}{{else}}/shared/img/default-user-profile-picture.jpg{{/if}}" title="{{full_name}}"/>
|
||||||
<button class="button-change-avatar">Edit Picture</button>
|
<button class="button-change-avatar js-modal-profile-picture">Edit Picture</button>
|
||||||
</figure>
|
</figure>
|
||||||
<label>
|
<label>
|
||||||
<input type="url" value="{{full_name}}" id="user-name" placeholder="Joe Bloggs" autocapitalize="off" autocorrect="off">
|
<input type="url" value="{{full_name}}" id="user-name" placeholder="Joe Bloggs" autocapitalize="off" autocorrect="off">
|
||||||
|
|
|
@ -181,19 +181,7 @@
|
||||||
this.showUpload('#icon', 'icon', settings.icon);
|
this.showUpload('#icon', 'icon', settings.icon);
|
||||||
},
|
},
|
||||||
showUpload: function (id, key, src) {
|
showUpload: function (id, key, src) {
|
||||||
var self = this;
|
var self = this, upload = new Ghost.Models.uploadModal({'id': id, 'key': key, 'src': src, 'accept': {
|
||||||
this.addSubview(new Ghost.Views.Modal({
|
|
||||||
model: {
|
|
||||||
options: {
|
|
||||||
close: false,
|
|
||||||
type: "action",
|
|
||||||
style: ["wide"],
|
|
||||||
animation: 'fade',
|
|
||||||
afterRender: function () {
|
|
||||||
this.$('.js-drop-zone').upload();
|
|
||||||
},
|
|
||||||
confirm: {
|
|
||||||
accept: {
|
|
||||||
func: function () { // The function called on acceptance
|
func: function () { // The function called on acceptance
|
||||||
var data = {};
|
var data = {};
|
||||||
data[key] = this.$('.js-upload-target').attr('src');
|
data[key] = this.$('.js-upload-target').attr('src');
|
||||||
|
@ -206,22 +194,10 @@
|
||||||
},
|
},
|
||||||
buttonClass: "button-save right",
|
buttonClass: "button-save right",
|
||||||
text: "Save" // The accept button text
|
text: "Save" // The accept button text
|
||||||
},
|
}});
|
||||||
reject: {
|
|
||||||
func: function () { // The function called on rejection
|
this.addSubview(new Ghost.Views.Modal({
|
||||||
return true;
|
model: upload
|
||||||
},
|
|
||||||
buttonClass: true,
|
|
||||||
text: "Cancel" // The reject button text
|
|
||||||
}
|
|
||||||
},
|
|
||||||
id: id,
|
|
||||||
src: src
|
|
||||||
},
|
|
||||||
content: {
|
|
||||||
template: 'uploadImage'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
templateName: 'settings/general',
|
templateName: 'settings/general',
|
||||||
|
@ -274,7 +250,38 @@
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
'click .button-save': 'saveUser',
|
'click .button-save': 'saveUser',
|
||||||
'click .button-change-password': 'changePassword'
|
'click .button-change-password': 'changePassword',
|
||||||
|
'click .js-modal-cover-picture': 'showCoverPicture',
|
||||||
|
'click .js-modal-profile-picture': 'showProfilePicture'
|
||||||
|
},
|
||||||
|
showCoverPicture: function () {
|
||||||
|
var user = this.model.toJSON();
|
||||||
|
this.showUpload('#user-cover-picture', 'cover_picture', user.cover_picture);
|
||||||
|
},
|
||||||
|
showProfilePicture: function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var user = this.model.toJSON();
|
||||||
|
this.showUpload('#user-profile-picture', 'profile_picture', user.profile_picture);
|
||||||
|
},
|
||||||
|
showUpload: function (id, key, src) {
|
||||||
|
var self = this, upload = new Ghost.Models.uploadModal({'id': id, 'key': key, 'src': src, 'accept': {
|
||||||
|
func: function () { // The function called on acceptance
|
||||||
|
var data = {};
|
||||||
|
data[key] = this.$('.js-upload-target').attr('src');
|
||||||
|
self.model.save(data, {
|
||||||
|
success: self.saveSuccess,
|
||||||
|
error: self.saveError
|
||||||
|
});
|
||||||
|
self.render();
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
buttonClass: "button-save right",
|
||||||
|
text: "Save" // The accept button text
|
||||||
|
}});
|
||||||
|
|
||||||
|
this.addSubview(new Ghost.Views.Modal({
|
||||||
|
model: upload
|
||||||
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue