From c43d860a3f245d3ba31d5c5ff0cc354d8cd94184 Mon Sep 17 00:00:00 2001 From: Sebastian Gierlinger Date: Wed, 23 Jul 2014 12:41:31 +0200 Subject: [PATCH] Transfer Ownership closes #3364 (special thanks to @jaswilli) closes #3087 - added modal - added controller --- .../controllers/modals/transfer-owner.js | 45 +++++++++++++++++++ core/client/initializers/popover.js | 1 + core/client/models/post.js | 3 -- core/client/models/role.js | 5 --- core/client/models/tag.js | 4 -- core/client/models/user.js | 3 -- .../templates/modals/transfer-owner.hbs | 6 +++ core/client/templates/settings/users/user.hbs | 4 +- core/client/templates/user-actions-menu.hbs | 4 +- 9 files changed, 56 insertions(+), 19 deletions(-) create mode 100644 core/client/controllers/modals/transfer-owner.js create mode 100644 core/client/templates/modals/transfer-owner.hbs diff --git a/core/client/controllers/modals/transfer-owner.js b/core/client/controllers/modals/transfer-owner.js new file mode 100644 index 0000000000..b341c62b71 --- /dev/null +++ b/core/client/controllers/modals/transfer-owner.js @@ -0,0 +1,45 @@ +var TransferOwnerController = Ember.Controller.extend({ + + actions: { + confirmAccept: function () { + var user = this.get('model'), + self = this; + + // Get owner role + this.store.find('role').then(function (result) { + return result.findBy('name', 'Owner'); + }).then(function (ownerRole) { + // remove roles and assign owner role + user.get('roles').clear(); + user.get('roles').pushObject(ownerRole); + return user.save({ format: false }); + }).then(function (model) { + self.notifications.closePassive(); + self.notifications.showSuccess('Settings successfully saved.'); + return model; + }).catch(function (errors) { + self.notifications.closePassive(); + self.notifications.showErrors(errors); + }).finally(function () { + self.get('popover').closePopovers(); + }); + }, + + confirmReject: function () { + return false; + } + }, + + confirm: { + accept: { + text: 'YEP - I\'M SURE', + buttonClass: 'button-delete' + }, + reject: { + text: 'CANCEL', + buttonClass: 'button' + } + } +}); + +export default TransferOwnerController; \ No newline at end of file diff --git a/core/client/initializers/popover.js b/core/client/initializers/popover.js index 58afaffc10..0bc05d895f 100644 --- a/core/client/initializers/popover.js +++ b/core/client/initializers/popover.js @@ -22,6 +22,7 @@ var popoverInitializer = { application.inject('component:gh-popover', 'popover', 'popover:service'); application.inject('component:gh-popover-button', 'popover', 'popover:service'); application.inject('controller:modals.delete-post', 'popover', 'popover:service'); + application.inject('controller:modals.transfer-owner', 'popover', 'popover:service'); application.inject('route:application', 'popover', 'popover:service'); } }; diff --git a/core/client/models/post.js b/core/client/models/post.js index 93ae598464..879a88774f 100644 --- a/core/client/models/post.js +++ b/core/client/models/post.js @@ -18,10 +18,7 @@ var Post = DS.Model.extend(NProgressSaveMixin, ValidationEngine, { meta_title: DS.attr('string'), meta_description: DS.attr('string'), author: DS.belongsTo('user', { async: true }), - created_at: DS.attr('moment-date'), - created_by: DS.belongsTo('user', { async: true }), updated_at: DS.attr('moment-date'), - updated_by: DS.belongsTo('user', { async: true }), published_at: DS.attr('moment-date'), published_by: DS.belongsTo('user', { async: true }), tags: DS.hasMany('tag', { embedded: 'always' }), diff --git a/core/client/models/role.js b/core/client/models/role.js index bcff3d202d..c3d8023844 100644 --- a/core/client/models/role.js +++ b/core/client/models/role.js @@ -2,11 +2,6 @@ var Role = DS.Model.extend({ uuid: DS.attr('string'), name: DS.attr('string'), description: DS.attr('string'), - created_at: DS.attr('moment-date'), - created_by: DS.belongsTo('user', { async: true }), - updated_at: DS.attr('moment-date'), - updated_by: DS.belongsTo('user', { async: true }), - lowerCaseName: Ember.computed('name', function () { return this.get('name').toLocaleLowerCase(); }) diff --git a/core/client/models/tag.js b/core/client/models/tag.js index e9d1b22a35..bd9295f509 100644 --- a/core/client/models/tag.js +++ b/core/client/models/tag.js @@ -6,10 +6,6 @@ var Tag = DS.Model.extend({ parent_id: DS.attr('number'), meta_title: DS.attr('string'), meta_description: DS.attr('string'), - created_at: DS.attr('moment-date'), - created_by: DS.belongsTo('user', {async: true}), - updated_at: DS.attr('moment-date'), - updated_by: DS.belongsTo('user', {async: true}) }); export default Tag; \ No newline at end of file diff --git a/core/client/models/user.js b/core/client/models/user.js index 8e6e78459d..01dab00d0e 100644 --- a/core/client/models/user.js +++ b/core/client/models/user.js @@ -20,9 +20,6 @@ var User = DS.Model.extend(NProgressSaveMixin, ValidationEngine, { meta_description: DS.attr('string'), last_login: DS.attr('moment-date'), created_at: DS.attr('moment-date'), - created_by: DS.belongsTo('user', { async: true }), - updated_at: DS.attr('moment-date'), - updated_by: DS.belongsTo('user', { async: true }), roles: DS.hasMany('role', { embedded: 'always' }), diff --git a/core/client/templates/modals/transfer-owner.hbs b/core/client/templates/modals/transfer-owner.hbs new file mode 100644 index 0000000000..e7783f3d2b --- /dev/null +++ b/core/client/templates/modals/transfer-owner.hbs @@ -0,0 +1,6 @@ +{{#gh-modal-dialog action="closeModal" showClose=true type="action" style="wide,centered" animation="fade" + title="Transfer Ownership" confirm=confirm}} + +

Are you sure you want to transfer the ownership of this blog? You will not be able to undo this action.

+ +{{/gh-modal-dialog}} diff --git a/core/client/templates/settings/users/user.hbs b/core/client/templates/settings/users/user.hbs index 02c1908c0b..7489e34140 100644 --- a/core/client/templates/settings/users/user.hbs +++ b/core/client/templates/settings/users/user.hbs @@ -10,13 +10,13 @@
- {{!-- {{#gh-popover-button popoverName="user-actions-menu" tagName="a" classNames="button only-has-icon user-actions-cog" title="User Actions"}} + {{#gh-popover-button popoverName="user-actions-menu" tagName="a" classNames="button only-has-icon user-actions-cog" title="User Actions"}} {{/gh-popover-button}} {{#gh-popover name="user-actions-menu" classNames="user-actions-menu menu-drop-right"}} {{render "user-actions-menu" model}} - {{/gh-popover}} --}} + {{/gh-popover}}
diff --git a/core/client/templates/user-actions-menu.hbs b/core/client/templates/user-actions-menu.hbs index 3d5f85f361..1e3af8c52d 100644 --- a/core/client/templates/user-actions-menu.hbs +++ b/core/client/templates/user-actions-menu.hbs @@ -1,2 +1,2 @@ -Make Owner -Delete User \ No newline at end of file +Make Owner +Delete User \ No newline at end of file