ES6: A bunch more controllers

This commit is contained in:
Robin Ward 2014-05-06 11:48:04 -04:00
parent a0221ce5e5
commit efcf99c21d
7 changed files with 44 additions and 42 deletions

View File

@ -6,7 +6,7 @@
@namespace Discourse
@module Discourse
**/
Discourse.FlagActionTypeController = Discourse.ObjectController.extend({
export default Discourse.ObjectController.extend({
needs: ['flag'],
message: Em.computed.alias('controllers.flag.message'),

View File

@ -7,7 +7,7 @@
@uses Discourse.ModalFunctionality
@module Discourse
**/
Discourse.FlagController = Discourse.ObjectController.extend(Discourse.ModalFunctionality, {
export default Discourse.ObjectController.extend(Discourse.ModalFunctionality, {
onShow: function() {
this.set('selected', null);

View File

@ -0,0 +1,36 @@
/**
The modal for when the user has forgotten their password
@class ForgotPasswordController
@extends Discourse.Controller
@namespace Discourse
@uses Discourse.ModalFunctionality
@module Discourse
**/
export default Discourse.Controller.extend(Discourse.ModalFunctionality, {
// You need a value in the field to submit it.
submitDisabled: function() {
return this.blank('accountEmailOrUsername');
}.property('accountEmailOrUsername'),
actions: {
submit: function() {
if (!this.get('accountEmailOrUsername')) return false;
Discourse.ajax("/session/forgot_password", {
data: { login: this.get('accountEmailOrUsername') },
type: 'POST'
});
// don't tell people what happened, this keeps it more secure (ensure same on server)
if (this.get('accountEmailOrUsername').match(/@/)) {
this.flash(I18n.t('forgot_password.complete_email', {email: this.get('accountEmailOrUsername')}));
} else {
this.flash(I18n.t('forgot_password.complete_username', {username: this.get('accountEmailOrUsername')}));
}
return false;
}
}
});

View File

@ -1,34 +0,0 @@
/**
The modal for when the user has forgotten their password
@class ForgotPasswordController
@extends Discourse.Controller
@namespace Discourse
@uses Discourse.ModalFunctionality
@module Discourse
**/
Discourse.ForgotPasswordController = Discourse.Controller.extend(Discourse.ModalFunctionality, {
// You need a value in the field to submit it.
submitDisabled: function() {
return this.blank('accountEmailOrUsername');
}.property('accountEmailOrUsername'),
submit: function() {
if (!this.get('accountEmailOrUsername')) return false;
Discourse.ajax("/session/forgot_password", {
data: { login: this.get('accountEmailOrUsername') },
type: 'POST'
});
// don't tell people what happened, this keeps it more secure (ensure same on server)
if (this.get('accountEmailOrUsername').match(/@/)) {
this.flash(I18n.t('forgot_password.complete_email', {email: this.get('accountEmailOrUsername')}));
} else {
this.flash(I18n.t('forgot_password.complete_username', {username: this.get('accountEmailOrUsername')}));
}
return false;
}
});

View File

@ -6,7 +6,7 @@
@namespace Discourse
@module Discourse
**/
Discourse.GroupController = Discourse.ObjectController.extend({
export default Discourse.ObjectController.extend({
counts: null,
// It would be nice if bootstrap marked action lists as selected when their links

View File

@ -1,7 +1,7 @@
<div class="modal-body flag-modal">
<form>
{{#each flagsAvailable itemController="flagActionType"}}
{{#each flagsAvailable itemController="flag-action-type"}}
<div class='controls'>
<label class='radio'>
<input type='radio' id="radio_{{unbound name_key}}" {{action changePostActionType this}} name='post_action_type_index'> <strong>{{formattedName}}</strong>

View File

@ -13,10 +13,10 @@ var buildAdminUser = function(args) {
}, args || {}));
};
module("Discourse.FlagController canDeleteSpammer");
module("controller:flag canDeleteSpammer");
test("canDeleteSpammer not staff", function(){
var flagController = testController(Discourse.FlagController, buildPost());
var flagController = controllerFor('flag', buildPost());
this.stub(Discourse.User, 'currentProp').withArgs('staff').returns(false);
flagController.set('selected', Discourse.PostActionType.create({name_key: 'spam'}));
equal(flagController.get('canDeleteSpammer'), false, 'false if current user is not staff');
@ -29,7 +29,7 @@ var canDeleteSpammer = function(test, postActionType, expected, testName) {
test("canDeleteSpammer spam not selected", function(){
this.stub(Discourse.User, 'currentProp').withArgs('staff').returns(true);
this.flagController = testController(Discourse.FlagController, buildPost());
this.flagController = controllerFor('flag', buildPost());
this.flagController.set('userDetails', buildAdminUser({can_delete_all_posts: true, can_be_deleted: true}));
canDeleteSpammer(this, 'off_topic', false, 'false if current user is staff, but selected is off_topic');
canDeleteSpammer(this, 'inappropriate', false, 'false if current user is staff, but selected is inappropriate');
@ -39,7 +39,7 @@ test("canDeleteSpammer spam not selected", function(){
test("canDeleteSpammer spam selected", function(){
this.stub(Discourse.User, 'currentProp').withArgs('staff').returns(true);
this.flagController = testController(Discourse.FlagController, buildPost());
this.flagController = controllerFor('flag', buildPost());
this.flagController.set('userDetails', buildAdminUser({can_delete_all_posts: true, can_be_deleted: true}));
canDeleteSpammer(this, 'spam', true, 'true if current user is staff, selected is spam, posts and user can be deleted');