summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2016-01-14 16:14:39 -0800
committerelijah <elijah@riseup.net>2016-01-14 16:14:39 -0800
commit6dba1392a29a003c3334259a222061f29ff04b13 (patch)
treee3161cf87ecec5ebc095adf55f66db1e21c17cbb /app
parentdd2518c40ab06f51d0f7380f1521087d3a4fbd5f (diff)
added UI for invite codes
Diffstat (limited to 'app')
-rw-r--r--app/assets/stylesheets/leap.scss10
-rw-r--r--app/controllers/invite_codes_controller.rb35
-rw-r--r--app/models/invite_code.rb11
-rw-r--r--app/views/invite_codes/_invite_code.html.haml9
-rw-r--r--app/views/invite_codes/index.html.haml20
-rw-r--r--app/views/layouts/_header.html.haml2
6 files changed, 80 insertions, 7 deletions
diff --git a/app/assets/stylesheets/leap.scss b/app/assets/stylesheets/leap.scss
index 5bc3c10..abbfc88 100644
--- a/app/assets/stylesheets/leap.scss
+++ b/app/assets/stylesheets/leap.scss
@@ -245,6 +245,16 @@ input, textarea {
}
//
+// INVITES
+//
+
+input.invite-code {
+ background: none;
+ border: none;
+ cursor: pointer;
+}
+
+//
// STICKY FOOTER for BOOSTRAP 2
// http://getbootstrap.com/2.3.2/examples/sticky-footer.html
// when upgrading to bootstrap 3, use this instead:
diff --git a/app/controllers/invite_codes_controller.rb b/app/controllers/invite_codes_controller.rb
new file mode 100644
index 0000000..6a7fef3
--- /dev/null
+++ b/app/controllers/invite_codes_controller.rb
@@ -0,0 +1,35 @@
+class InviteCodesController < ApplicationController
+
+ respond_to :html
+ before_filter :require_login
+ before_filter :require_admin
+ before_filter :fetch_invite, only: :destroy
+
+ def index
+ @invite = InviteCode.new # for the creation form.
+ @invites = InviteCode.all.page(params[:page]).per(APP_CONFIG[:pagination_size])
+ respond_with @invites
+ end
+
+ def create
+ @invite = InviteCode.new(params[:invite_code])
+ @invite.save # throws exception on error (!)
+ flash[:success] = t('created') + " #{@invite.invite_code}"
+ rescue
+ flash[:error] = "could not save invite code" # who knows why, invite.errors is empty
+ ensure
+ redirect_to invite_codes_path
+ end
+
+ def destroy
+ @invite.destroy
+ redirect_to invite_codes_path
+ end
+
+ protected
+
+ def fetch_invite
+ @invite = InviteCode.find(params[:id])
+ end
+
+end
diff --git a/app/models/invite_code.rb b/app/models/invite_code.rb
index 5666a4f..9c6df66 100644
--- a/app/models/invite_code.rb
+++ b/app/models/invite_code.rb
@@ -15,13 +15,12 @@ class InviteCode < CouchRest::Model::Base
end
def initialize(attributes = {}, options = {})
- if !attributes.has_key?("_id")
- attributes[:id] = InviteCode.generate_invite
- end
-
+ attributes[:id] = attributes["invite_code"] || InviteCode.generate_invite
super(attributes, options)
-
- write_attribute('invite_code', attributes[:id]) if new?
+ if new?
+ write_attribute('invite_code', attributes[:id])
+ write_attribute('max_uses', attributes[:max_uses] || 1)
+ end
end
def self.generate_invite
diff --git a/app/views/invite_codes/_invite_code.html.haml b/app/views/invite_codes/_invite_code.html.haml
new file mode 100644
index 0000000..a3c420d
--- /dev/null
+++ b/app/views/invite_codes/_invite_code.html.haml
@@ -0,0 +1,9 @@
+%tr
+ %td
+ = simple_date(invite_code.created_at)
+ %td
+ %input.invite-code{:value => invite_code.invite_code}
+ %td
+ = "#{invite_code.invite_count}/#{invite_code.max_uses}"
+ %td
+ = btn t(".destroy", cascade: true), invite_code_path(invite_code), :method => 'delete'
diff --git a/app/views/invite_codes/index.html.haml b/app/views/invite_codes/index.html.haml
new file mode 100644
index 0000000..40fccdf
--- /dev/null
+++ b/app/views/invite_codes/index.html.haml
@@ -0,0 +1,20 @@
+- @show_navigation = false
+
+= form_for @invite, :url => { :action => "create" } do |f|
+ %table
+ %tr
+ %td= t "code"
+ %td= t "uses"
+ %td
+ %tr
+ %td= f.text_field :invite_code, style: 'width: 10em'
+ %td= f.text_field :max_uses, style: 'width: 4em'
+ %td= f.submit t("helpers.submit.invites.create"), style: 'margin-bottom: 10px', class: 'btn btn-default'
+
+= table @invites, %w(created code uses actions)
+
+-# select the text of the invite code when you click on it:
+:javascript
+ $("input.invite-code").focus(function(){
+ this.select();
+ }); \ No newline at end of file
diff --git a/app/views/layouts/_header.html.haml b/app/views/layouts/_header.html.haml
index fd654d8..6263bc3 100644
--- a/app/views/layouts/_header.html.haml
+++ b/app/views/layouts/_header.html.haml
@@ -1,7 +1,7 @@
- if admin?
%ul.nav.nav-pills.admin-area
= render partial: 'common/navigation_item',
- collection: [:users, :identities, :tickets]
+ collection: [:users, :identities, :invite_codes, :tickets]
= link_to_navigation :logout, logout_path, :method => :delete
- if @user && @show_navigation
.lead