diff --git a/Gemfile b/Gemfile
index a2cb67a..8cba61f 100644
--- a/Gemfile
+++ b/Gemfile
@@ -45,15 +45,6 @@ group :development, :test do
gem 'mysql2', '~> 0.3.18'
end
-gem 'slim-rails'
-gem 'activeadmin', '~> 1.0.0.pre2'
-gem 'devise'
-gem 'bullet', :group => 'development'
-gem 'jquery-ui-rails'
-gem 'exception_notification'
-gem 'pundit'
-gem 'bootstrap-sass', '~> 3.3.5'
-
group :test do
gem 'cucumber-rails', :require => false
# database_cleaner is not required, but highly recommended
@@ -71,4 +62,7 @@ gem 'activeadmin', '~> 1.0.0.pre2'
gem 'devise'
gem 'bullet', :group => 'development'
gem 'jquery-ui-rails'
-gem 'exception_notification'
\ No newline at end of file
+gem 'pundit'
+gem 'bootstrap-sass', '~> 3.3.5'
+gem 'exception_notification'
+gem 'rails_autolink'
\ No newline at end of file
diff --git a/Gemfile.lock b/Gemfile.lock
index 3412df3..2ed02b8 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -184,6 +184,8 @@ GEM
rails_12factor (0.0.3)
rails_serve_static_assets
rails_stdout_logging
+ rails_autolink (1.1.6)
+ rails (> 3.1)
rails_serve_static_assets (0.0.4)
rails_stdout_logging (0.0.4)
railties (4.2.0)
@@ -295,6 +297,7 @@ DEPENDENCIES
pundit
rails (= 4.2.0)
rails_12factor
+ rails_autolink
rspec-rails (~> 3.0)
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
diff --git a/app/assets/javascripts/showbill.coffee b/app/assets/javascripts/showbill.coffee
new file mode 100644
index 0000000..ddaf463
--- /dev/null
+++ b/app/assets/javascripts/showbill.coffee
@@ -0,0 +1,33 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://coffeescript.org/
+
+$(document).on "ready", ->
+ $('.showbill').on "keyup", ->
+ $.ajax({method: "PATCH", url: "showbill/" + $(this).attr("id"), data: make_data($(this)) , dataType:"script"})
+
+ # converts div.html to textarea.text
+ $('.showbill-div').on "click", ->
+ if $('textarea').is('.showbill')
+ text = $('.showbill-div').html().replace( /
/g,"\n")
+ $('.showbill').text(disable_links(clean_text(text)))
+ $('.showbill').show().focus()
+ $('.showbill-div').hide()
+
+ $('.showbill').on "blur", ->
+ $('.showbill').hide()
+ $('.showbill-div').show()
+
+make_data = (item) ->
+ return {} =
+ #we'll need description in one line. Replacing \n by
to don't lose them.
+ description: item.val().replace(/\n/g, "
")
+ id: $(item).attr("id")
+
+#extracts link_text from link_tag by deleting and
+disable_links = (text) ->
+ text.replace(//g, "").replace(/<\/a>/g,"")
+
+clean_text = (text) ->
+ text.replace(/^\n*\s*\n*\s*/,"").replace(/\s*$/,"")
+
diff --git a/app/controllers/showbill_controller.rb b/app/controllers/showbill_controller.rb
new file mode 100644
index 0000000..19bd141
--- /dev/null
+++ b/app/controllers/showbill_controller.rb
@@ -0,0 +1,13 @@
+class ShowbillController < ApplicationController
+
+ def update
+
+ if current_user.present?
+ @error = t(:error_update_text) unless @showbill = Showbill_singleton.instance.update(params[:description])
+ else
+ @error = t(:you_can_not_edit_it)
+ end
+
+ end
+
+end
diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb
index 197f1bc..907ecb4 100644
--- a/app/controllers/user_controller.rb
+++ b/app/controllers/user_controller.rb
@@ -28,5 +28,6 @@ def users_to_show
else
@users = User.order(:name)
end
+ @showbill = Showbill_singleton.instance.text
end
end
diff --git a/app/helpers/showbill_helper.rb b/app/helpers/showbill_helper.rb
new file mode 100644
index 0000000..10627c7
--- /dev/null
+++ b/app/helpers/showbill_helper.rb
@@ -0,0 +1,2 @@
+module ShowbillHelper
+end
diff --git a/app/models/showbill_singleton.rb b/app/models/showbill_singleton.rb
new file mode 100644
index 0000000..b310ae4
--- /dev/null
+++ b/app/models/showbill_singleton.rb
@@ -0,0 +1,21 @@
+require 'singleton'
+
+class Showbill_singleton
+ include Singleton
+
+ attr_accessor :text
+
+ def initialize
+ @text = "Some default description"
+ end
+
+ def update(text)
+ text.present? ? @text = text : false
+ end
+
+ def text
+ @text.present? ? @text : initialize
+ end
+
+
+end
\ No newline at end of file
diff --git a/app/views/showbill/_showbill.html.slim b/app/views/showbill/_showbill.html.slim
new file mode 100644
index 0000000..1f9e8d2
--- /dev/null
+++ b/app/views/showbill/_showbill.html.slim
@@ -0,0 +1,7 @@
+.row
+ .col-md-12 class = "showbill-div"
+ = auto_link(@showbill)
+.row
+ - if current_user.present?
+ .col-md-12
+ = text_area_tag("showbill", @showbill, {class: "showbill width-max-avail", hidden: "hidden"})
\ No newline at end of file
diff --git a/app/views/showbill/update.js.slim b/app/views/showbill/update.js.slim
new file mode 100644
index 0000000..80b5ea5
--- /dev/null
+++ b/app/views/showbill/update.js.slim
@@ -0,0 +1,9 @@
+- if @error
+ | $("#error_label").text("
+ = @error
+ | ");
+ | $("#error_row").show();
+- else
+ | $("#error_row").hide();
+ | $('.showbill-div').text("");
+ | $('.showbill-div').append('#{auto_link(@showbill)}');
\ No newline at end of file
diff --git a/app/views/user/index.html.slim b/app/views/user/index.html.slim
index c237c59..d5e7ad0 100644
--- a/app/views/user/index.html.slim
+++ b/app/views/user/index.html.slim
@@ -1,3 +1,5 @@
+= render :partial => '/showbill/showbill', :showbills => @showbills
+
- @users.each do |user|
.row id = user.name_without_spaces
.col-md-2 class = "name bold"
diff --git a/app/views/user/update.js.slim b/app/views/user/update.js.slim
index 9843362..ccc2f8d 100644
--- a/app/views/user/update.js.slim
+++ b/app/views/user/update.js.slim
@@ -4,3 +4,5 @@
= @error
| ");
| $("#error_row").show();
+- else
+ | $("#error_row").hide();
\ No newline at end of file
diff --git a/config/locales/en.yml b/config/locales/en.yml
index a70cb80..4c9d7e5 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -36,3 +36,4 @@ en:
user_details: "User Details"
sign_up: "Sign up"
or: "or"
+ you_can_not_edit_it: "You can not edit it!"
diff --git a/config/routes.rb b/config/routes.rb
index 15e9606..5163e11 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,7 +1,9 @@
Rails.application.routes.draw do
+
devise_for :users, :controllers => {:registrations => "user/registrations"}
resources :user, only: [:index, :update]
+ resources :showbill, only: [:update]
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)