Commit 751c77d31ed4bbf4f3edd09c5be4eb91978af8e1

Authored by Karpikau Andrei
1 parent b00b9ab0

check errors, add reset password function

... ... @@ -1944,6 +1944,7 @@ var flashHandler = function(e, params) {
1944 1944 var type = params.type;
1945 1945 if (type == 'alert') type = 'info';
1946 1946 if (type == 'notice') type = 'info';
  1947 + if (type == 'error') type = 'danger';
1947 1948
1948 1949 $.notify(params.message, {
1949 1950 status: type,
... ...
... ... @@ -56,6 +56,8 @@ jQuery(document).ready(function(){
56 56 $cell.data('class', class_value);
57 57 }
58 58
  59 + $this.popover('hide');
  60 +
59 61 return false;
60 62 });
61 63
... ... @@ -269,6 +271,8 @@ jQuery(document).ready(function(){
269 271 $('.html-generator').on('click', '.col-operation .col-content, .row-operation .col-content', function(){
270 272 var $this = $(this);
271 273
  274 + $('body').trigger('click');
  275 +
272 276 if($this.closest('.row-element-block').length > 0){
273 277 var $cell = $this.closest('.row-element-block');
274 278 }else{
... ... @@ -291,6 +295,16 @@ jQuery(document).ready(function(){
291 295 $('#work_area').slideDown('slow', function(){
292 296 initializeFieldForm($('#page_content_form'));
293 297 });
  298 +
  299 + $('#work_area .editor-content').find('.cancel-content').click(function(){
  300 + $('#work_area').slideUp('fast', function(){
  301 + $('#work_area .editor-content').html('');
  302 + $('#structure_area').slideDown('slow', function(){
  303 + });
  304 + });
  305 + return false;
  306 + });
  307 +
294 308 });
295 309 }
296 310 });
... ...
... ... @@ -26,6 +26,27 @@ module Kanjai
26 26 def edit
27 27 @page_template = PageTemplate.find(params[:id])
28 28 @url = @page_template.file_expiring_url
  29 +
  30 + lang = params[:lang]
  31 +
  32 + if @page_template.unzip
  33 + exist_markers = @page_template.page_content_markers.where(lang: lang).collect(&:marker)
  34 +
  35 + @page_template.template_statics.where.not(marker: exist_markers).each do |item|
  36 + @page_template.page_content_markers.create(
  37 + marker: item.marker,
  38 + marker_type: item.marker_type,
  39 + marker_name: item.marker_name,
  40 + lang: lang
  41 + )
  42 + end
  43 +
  44 +
  45 +
  46 + @markers = @page_template.page_content_markers.where(lang: lang)
  47 + end
  48 +
  49 +
29 50 end
30 51
31 52 def update
... ...
  1 +require 'unobtrusive_flash'
  2 +
  3 +module Kanjai
  4 + module Admin
  5 + class PasswordsController < Devise::PasswordsController
  6 + include UnobtrusiveFlash::ControllerMixin
  7 + layout 'kanjai/admin_login'
  8 +
  9 + after_action :prepare_unobtrusive_flash
  10 +
  11 + def create
  12 + self.resource = resource_class.send_reset_password_instructions(resource_params)
  13 + yield resource if block_given?
  14 +
  15 + if successfully_sent?(resource)
  16 + respond_with({}, location: after_sending_reset_password_instructions_path_for(resource_name))
  17 + else
  18 + flash[:error] = t('password_reset_error')
  19 + respond_with(resource)
  20 + end
  21 + end
  22 +
  23 + protected
  24 +
  25 + def after_sign_in_path_for(resource)
  26 + admin_dashboard_path
  27 + end
  28 +
  29 + def after_sign_out_path_for(resource)
  30 + new_admin_user_session_path
  31 + end
  32 +
  33 + end
  34 + end
  35 +end
\ No newline at end of file
... ...
... ... @@ -2,7 +2,7 @@ module Kanjai
2 2 class AdminUser < ActiveRecord::Base
3 3 # Include default devise modules. Others available are:
4 4 # :confirmable, :lockable, :timeoutable and :omniauthable
5   - devise :database_authenticatable, :rememberable, :trackable, :validatable
  5 + devise :database_authenticatable, :rememberable, :trackable, :validatable, :recoverable
6 6
7 7
8 8 end
... ...
... ... @@ -18,7 +18,7 @@ module Kanjai
18 18 has_many :page_data, dependent: :destroy
19 19 accepts_nested_attributes_for :page_data
20 20
21   - #validates :title, :url, presence: true
  21 + validates :title, presence: true
22 22
23 23 #serialize :template_content, Array
24 24
... ...
... ... @@ -189,6 +189,16 @@ module Kanjai
189 189 url
190 190 end
191 191
  192 + def human_title
  193 + if original_file_name.to_s.empty?
  194 + I18n.t('admin.template_status.not_file')
  195 + elsif unzip
  196 + I18n.t('admin.template_status.unzip')
  197 + else
  198 + I18n.t('admin.template_status.zip')
  199 + end
  200 + end
  201 +
192 202 private
193 203
194 204 def move_file
... ...
1   -<div class="container">
2   - <div class="col-md-4" style="float:none;margin:0 auto;">
3   - <h1>Forgot your password?</h1>
4   -
5   - <%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %>
6   - <%= devise_error_messages! %>
7   -
8   - <div class="form-group">
9   - <%= f.label :email %><br />
10   - <%= f.email_field :email, autofocus: true, :class => 'form-control' %>
11   - </div>
12   -
13   -
14   - <%= f.submit "Send me reset password instructions", :class => 'btn btn-default' %>
15   -
16   - <% end %>
17   -
18   - <%= render "devise/shared/links" %>
19   - </div>
20   -</div>
\ No newline at end of file
  1 +<div class="card-body">
  2 + <p class="text-center py-2"><%= t('password_reset_title') %></p>
  3 + <%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %>
  4 + <p class="text-center"><%= t('password_reset_text') %></p>
  5 + <div class="form-group"><label class="text-muted" for="resetInputEmail1"><%= t('password_reset_email') %></label>
  6 + <div class="input-group with-focus">
  7 + <%= f.email_field :email, autofocus: true, :class => 'form-control border-right-0', autocomplete: 'off' %>
  8 + <div class="input-group-append"><span class="input-group-text text-muted bg-transparent border-left-0"><em class="fa fa-envelope"></em></span></div>
  9 + </div>
  10 + </div><button class="btn btn-danger btn-block" type="submit">Reset</button>
  11 + <% end %>
  12 +</div>
... ...
... ... @@ -22,6 +22,9 @@
22 22 <%= t('admin.login.remember_me') %>
23 23 </label>
24 24 </div>
  25 + <div class="float-right">
  26 + <%= link_to t('forgot_password'), new_password_path(resource_name), class: 'text-muted' %>
  27 + </div>
25 28 <% end -%>
26 29
27 30 </div>
... ...
... ... @@ -21,9 +21,14 @@
21 21
22 22 <div class="card-footer mt-20">
23 23 <div class="clearfix">
24   - <div class="float-right">
25   - <%= link_to t('actions.cancel'), admin_admin_users_url, class: 'btn btn-secondary' %>
26   - <button class="btn btn-primary" type="submit"><%= t('actions.save') %></button>
  24 + <div class="row">
  25 + <div class="col-md-6">
  26 + <p class="mt-1"><%= t('mandatory_fields') %></p>
  27 + </div>
  28 + <div class="col-md-6 text-right">
  29 + <%= link_to t('actions.cancel'), admin_admin_users_url, class: 'btn btn-secondary' %>
  30 + <button class="btn btn-primary" type="submit"><%= t('actions.save') %></button>
  31 + </div>
27 32 </div>
28 33 </div>
29 34 </div>
... ...
... ... @@ -22,9 +22,14 @@
22 22
23 23 <div class="card-footer mt-20">
24 24 <div class="clearfix">
25   - <div class="float-right">
26   - <%= link_to t('actions.cancel'), admin_page_langs_url, class: 'btn btn-secondary' %>
27   - <button class="btn btn-primary" type="submit"><%= t('actions.save') %></button>
  25 + <div class="row">
  26 + <div class="col-md-6">
  27 + <p class="mt-1"><%= t('mandatory_fields') %></p>
  28 + </div>
  29 + <div class="col-md-6 text-right">
  30 + <%= link_to t('actions.cancel'), admin_page_langs_url, class: 'btn btn-secondary' %>
  31 + <button class="btn btn-primary" type="submit"><%= t('actions.save') %></button>
  32 + </div>
28 33 </div>
29 34 </div>
30 35 </div>
... ...
... ... @@ -29,9 +29,14 @@
29 29
30 30 <div class="card-footer mt-20">
31 31 <div class="clearfix">
32   - <div class="float-right">
33   - <%= link_to t('actions.cancel'), admin_page_templates_url, class: 'btn btn-secondary' %>
34   - <button class="btn btn-primary" type="submit"><%= t('actions.save') %></button>
  32 + <div class="row">
  33 + <div class="col-md-6">
  34 + <p class="mt-1"><%= t('mandatory_fields') %></p>
  35 + </div>
  36 + <div class="col-md-6 text-right">
  37 + <%= link_to t('actions.cancel'), admin_page_templates_url, class: 'btn btn-secondary' %>
  38 + <button class="btn btn-primary" type="submit"><%= t('actions.save') %></button>
  39 + </div>
35 40 </div>
36 41 </div>
37 42 </div>
... ...
1 1 <div class="content-wrapper">
2 2 <div class="row">
3   - <div class="col-xl-12">
4   -
5   - <%= form_for @page_template, url: admin_page_template_url(@page_template), html: {class: 'form-horizontal ajax-file-upload-form simple_submit'} do |f| %>
6   - <div class="card card-default">
7   - <div class="card-header">
8   - <div class="card-title"><%= t('admin.templates.edit') %></div>
9   - </div>
10   - <%= render partial: 'form', locals: {f: f} %>
  3 + <div class="col-xl-12">
  4 + <div class="card card-default">
  5 + <div class="card-header">
  6 + <div class="card-title"><%= t('admin.templates.edit') %></div>
  7 + </div>
  8 +
  9 + <ul class="nav nav-tabs" role="tablist">
  10 + <li class="nav-item" role="presentation"><a class="nav-link <%= controller_name == 'page_templates' ? 'active' : '' %>" href="#general" aria-controls="general" role="tab" data-toggle="tab">General</a></li>
  11 + <li class="nav-item" role="presentation"><a class="nav-link <%= controller_name == 'page_templates2' ? 'active' : '' %>" href="#static" aria-controls="meta" role="tab" data-toggle="tab">Static</a></li>
  12 + <% if Kanjai::PageLang.count > 0 %>
  13 + <li class="choose-lang">
  14 + <div class="text-right">
  15 + <%= select_tag :choose_lang, options_for_select(Kanjai::PageLang.all.collect{|lang| [lang.title, lang.code, data: {url: edit_admin_page_template_url(@page_template, lang: lang.code)}] }, params[:lang]), class: 'form-control' %>
  16 + </div>
  17 + </li>
  18 + <% end %>
  19 + </ul><!-- Tab panes-->
  20 + <div class="tab-content">
  21 + <div class="tab-pane <%= controller_name == 'page_templates' ? 'active' : '' %>" id="general" role="tabpanel">
  22 + <%= form_for @page_template, url: admin_page_template_url(@page_template), html: {class: 'form-horizontal ajax-file-upload-form simple_submit'} do |f| %>
  23 + <%= render partial: 'form', locals: {f: f} %>
  24 + <% end %>
  25 + </div>
  26 +
  27 + <div class="tab-pane <%= controller_name == 'page_templates2' ? 'active' : '' %>" id="static" role="tabpanel">
  28 + <%= form_for(@page_template, :url => update_marker_admin_page_template_url, :html => {:method => 'POST', :class => "form-horizontal ajax-file-upload-form simple_submit"}) do |form| %>
  29 +
  30 + <%= form.fields_for :page_content_markers, @markers do |form2| %>
  31 +
  32 + <div class="form-group">
  33 + <%= form2.label :text_value, form2.object.marker, :class => "control-label" %>
  34 + <% if form2.object.marker_type == 'string' %>
  35 + <%= form2.text_field :text_value, :class => "form-control" %>
  36 + <% end %>
  37 + <% if form2.object.marker_type == 'text' %>
  38 + <%= form2.text_area :text_value, :class => "form-control page_html_content" %>
  39 + <% end %>
  40 + <% if form2.object.marker_type == 'file' %>
  41 + <% s3_direct_post = S3_BUCKET.presigned_post(key: "#{form2.object.get_file_path}${filename}", success_action_status: '201', acl: 'public-read') %>
  42 + <%= form2.file_field :text_value, :class => "", 'data-url' => s3_direct_post.url, 'data-form-data' => s3_direct_post.fields.to_json, 'data-host' => URI.parse(s3_direct_post.url).host , 'data-type' => 'zip' %>
  43 + <% if form2.object.text_value.present? %>
  44 + <%= link_to 'file', form2.object.text_value %>
  45 + <% end %>
  46 + <% end %>
  47 +
  48 + </div>
  49 +
  50 +
  51 + <% end %>
  52 +
  53 + <div class="card-footer mt-20">
  54 + <div class="clearfix">
  55 + <div class="float-right">
  56 + <%= link_to t('actions.cancel'), admin_page_templates_url, class: 'btn btn-secondary' %>
  57 + <button class="btn btn-primary save" type="submit"><%= t('actions.save') %></button>
  58 + </div>
  59 + </div>
  60 + </div>
  61 +
  62 + <% end %>
11 63 </div>
12   - <% end %>
  64 + </div>
13 65
  66 + </div>
14 67 </div>
15 68 </div>
16 69 </div>
... ...
... ... @@ -30,7 +30,7 @@
30 30 <% @collection.each do |item| %>
31 31 <tr id='<%= dom_id(item) %>'>
32 32 <td><%= item.title %></td>
33   - <td><%= (item.unzip ? 'unzip' : 'zip') %></td>
  33 + <td><%= item.human_title %></td>
34 34 <td><%= I18n.l(item.updated_at) %></td>
35 35 <td><%= item.notice %></td>
36 36 <td>
... ... @@ -41,9 +41,6 @@
41 41 <ul class="dropdown-menu">
42 42 <li class="dropdown-item"><%= link_to t('actions.edit'), edit_admin_page_template_url(item), class: 'dropdown-item' %></li>
43 43 <li class="dropdown-item"><%= link_to t('actions.delete'), admin_page_template_url(item), :class => 'delete-row-item dropdown-item' %></li>
44   - <% Kanjai::PageLang.all.each do |lang| %>
45   - <li class="dropdown-item"><%= link_to t('actions.edit_static_element', lang: lang.code), marker_admin_page_template_url(item, :lang => lang.code), class: 'dropdown-item' %></li>
46   - <% end %>
47 44 </ul>
48 45 </div>
49 46 </td>
... ...
... ... @@ -28,6 +28,7 @@
28 28
29 29 <%= render :partial => 'kanjai/shared/edit_resource_links', locals: {collection_url: admin_page_templates_url} %>
30 30
  31 +
31 32 <% end %>
32 33
33 34 </div>
\ No newline at end of file
... ...
... ... @@ -5,7 +5,7 @@
5 5
6 6 <% if @page.new_record? %>
7 7 <div class="form-group row">
8   - <%= form.label :title, Kanjai::Page.human_attribute_name(:title), :class => "col-md-2 col-form-label" %>
  8 + <%= form.label :title, Kanjai::Page.human_attribute_name(:title) + '*', :class => "col-md-2 col-form-label" %>
9 9 <div class="col-md-10">
10 10 <%= form.text_field :title, :class => "form-control" %>
11 11 <%= error_messages(@page, :title) %>
... ... @@ -57,17 +57,16 @@
57 57 </div>
58 58 </div>
59 59 </fieldset>
60   -
61 60 <% unless @page.new_record? %>
62 61 <fieldset>
63 62 <legend><%= t('admin.pages.edit_lang_content', :lang => params[:lang]) %></legend>
64   - <%= form.fields_for :page_data, @page.page_data.where(lang: params[:lang]) do |form2| %>
65   -
  63 + <%= form.fields_for :page_data, @page.page_data.select{|item| item.lang == params[:lang] } do |form2| %>
66 64
67 65 <div class="form-group row">
68 66 <%= form2.label :title, Kanjai::Page.human_attribute_name(:title) + '*', :class => "col-sm-2 col-form-label" %>
69 67 <div class="col-sm-10">
70   - <%= form2.text_field :title, :class => "form-control" %>
  68 + <%= form2.text_field :title, :class => "form-control #{@page.errors.include?('page_data.title') ? 'parsley-error' : ''}" %>
  69 + <%= error_messages(form.object, 'page_data.title') %>
71 70 </div>
72 71 </div>
73 72
... ... @@ -77,6 +76,7 @@
77 76 <%= form2.text_field :url, :class => "form-control" %>
78 77 </div>
79 78 </div>
  79 +
80 80 <% end %>
81 81 </fieldset>
82 82 <% end %>
... ... @@ -85,7 +85,7 @@
85 85 <div class="clearfix">
86 86 <div class="row">
87 87 <div class="col-md-6">
88   - <p class="mt-1">* Please at mandatory fields</p>
  88 + <p class="mt-1"><%= t('mandatory_fields') %></p>
89 89 </div>
90 90 <div class="col-md-6">
91 91 <div class="float-right">
... ...
... ... @@ -21,7 +21,7 @@
21 21 <div class="card-footer mt-20">
22 22 <div class="clearfix">
23 23 <div class="float-right">
24   - <%= link_to t('actions.cancel'), admin_pages_url, class: 'btn btn-secondary' %>
  24 + <%= link_to t('actions.cancel'), '#', class: 'btn btn-secondary cancel-content' %>
25 25 <button class="btn btn-primary" type="submit"><%= t('actions.save') %></button>
26 26 </div>
27 27 </div>
... ...
... ... @@ -7,7 +7,7 @@
7 7
8 8 <%= csrf_meta_tags %>
9 9
10   - <title>Angle - Bootstrap Admin Template</title><!-- =============== VENDOR STYLES ===============-->
  10 + <title><%= t('meta_title') %></title><!-- =============== VENDOR STYLES ===============-->
11 11 <!-- FONT AWESOME-->
12 12 <%= stylesheet_link_tag "kanjai/general" %>
13 13 </head>
... ...
... ... @@ -4,7 +4,7 @@
4 4 <head>
5 5 <meta charset="utf-8">
6 6 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
7   - <title>Angle - Bootstrap Admin Template</title>
  7 + <title><%= t('meta_title') %></title>
8 8 <%= stylesheet_link_tag "kanjai/general" %>
9 9 </head>
10 10
... ...
1 1 template = ERB.new File.new("#{Rails.root}/config/admin.yml").read
2 2 processed = template.result(binding)
3 3
4   -ADMIN_CONFIG = YAML.load(processed)[Rails.env]
\ No newline at end of file
  4 +ADMIN_CONFIG = YAML.load(processed)[Rails.env]
  5 +
  6 +ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
  7 + html_tag.html_safe
  8 +end
\ No newline at end of file
... ...
... ... @@ -35,6 +35,13 @@ en:
35 35 copyright: "© 2020 - kanjai.org"
36 36 logout: 'Logout'
37 37 please_wait: "Please, wait ..."
  38 + mandatory_fields: "* Mandatory fields"
  39 + meta_title: "Kanjai - Bootstrap CMS"
  40 + forgot_password: "Forgot your password?"
  41 + password_reset_title: "PASSWORD RESET"
  42 + password_reset_text: "Fill with your mail to receive instructions on how to reset your password."
  43 + password_reset_email: "Email address"
  44 + password_reset_error: "Can not send instrution, please check email"
38 45
39 46
40 47 date:
... ... @@ -78,6 +85,7 @@ en:
78 85 updated_at: "Updated at"
79 86 unzip: "Status"
80 87 notice: "Notice"
  88 + attachment: "Template"
81 89 kanjai/image:
82 90 name: "Name"
83 91 tags: "Tags"
... ... @@ -141,4 +149,8 @@ en:
141 149 empty_text: "You don't have template"
142 150 edit: "Edit template"
143 151 create: "Add new template"
  152 + template_status:
  153 + not_file: ""
  154 + unzip: "In Progress"
  155 + zip: "Ready"
144 156
... ...
... ... @@ -3,7 +3,7 @@ Kanjai::Engine.routes.draw do
3 3
4 4 devise_for :admin_users, {
5 5 path_names: {sign_in: 'login', sign_out: 'logout'},
6   - controllers: {sessions: 'kanjai/admin/sessions'},
  6 + controllers: {sessions: 'kanjai/admin/sessions', passwords: 'kanjai/admin/passwords'},
7 7 class_name: "Kanjai::AdminUser", module: :devise
8 8 }
9 9
... ...
1 1 module Kanjai
2   - VERSION = "0.0.150"
  2 + VERSION = "0.0.151"
3 3 end
... ...