partially implement modal

This commit is contained in:
Sam 2017-02-07 14:22:46 -05:00
parent c68a6652ec
commit f2d31b83a2
4 changed files with 68 additions and 3 deletions

View File

@ -0,0 +1,20 @@
import { default as computed } from 'ember-addons/ember-computed-decorators';
import { ajax } from 'discourse/lib/ajax';
import { popupAjaxError } from 'discourse/lib/ajax-error';
export default Ember.Controller.extend({
@computed("username")
disabled(username) {
return Ember.isEmpty(username);
},
actions: {
assign(){
return ajax('/assign/assign',{
type: 'PUT',
data: { username: this.get('username'), topic_id: 1 }
}).catch(popupAjaxError);
}
}
});

View File

@ -1,7 +1,16 @@
{{#d-modal-body title="discourse_assigns.assign_modal.title" class="assign"}}
hi there
{{i18n 'discourse_assigns.assign_modal.description'}}
{{user-selector
single=true
allowAny=false
excludeCurrentUser=false
includeMentionableGroups=false
hasGroups=false
usernames=username
placeholderKey=placeholderKey
autocomplete="off"}}
{{/d-modal-body}}
<div class="modal-footer">
I am the footer
{{d-button label='discourse_assigns.assign_modal.assign' icon=inviteIcon action="assign" class="btn-primary" disabled=disabled}}
</div>

View File

@ -4,3 +4,7 @@ en:
assign:
title: "Assign"
help: "Assign Topic to User"
assign_modal:
title: "Assign Topic"
description: "Enter the username of the person you'd like to assign this topic"
assign: "Assign"

View File

@ -1,4 +1,4 @@
# name: discourse-assigns
# name: discourse-assign
# about: Assign users to topics
# version: 0.1
# authors: Sam Saffron
@ -22,4 +22,36 @@ SQL
belongs_to :assigned_to, class_name: 'User'
belongs_to :assigned_by, class_name: 'User'
end
module ::DiscourseAssign
class Engine < ::Rails::Engine
engine_name "discourse_assign"
isolate_namespace DiscourseAssign
end
end
class ::DiscourseAssign::AssignController < Admin::AdminController
before_filter :ensure_logged_in
def assign
topic_id = params.require(:topic_id)
username = params.require(:username)
assigned = AssignedUser.where(topic_id: topic_id).first_or_initialize
assigned.assigned_to_id = User.where(username_lower: username.downcase).pluck(:id).first
assigned.assigned_by_id = current_user.id
assigned.save!
render json: {status: "ok"}
end
DiscourseAssign::Engine.routes.draw do
put "/assign" => "assign#assign"
end
Discourse::Application.routes.append do
mount ::DiscourseAssign::Engine, at: "/assign"
end
end
end