Commit 5f4e1dd271df86f1d6672436a6127a06ef83ca24

Authored by Karpikau Andrei
1 parent 76ad2fbc

check update tag

... ... @@ -1351,11 +1351,16 @@ $('body').on('click', '.delete-image-from-list', function(){
1351 1351
1352 1352 $('body').on('click', '.delete-tag-from-list', function(){
1353 1353 var $this = $(this),
  1354 + $label = $this.closest('label'),
1354 1355 url = $this.attr('href'),
1355 1356 title = "Are you sure? If files are assigned to this tag, the assignment is removed.";
1356 1357
1357 1358 bootbox.confirm(title, function(result) {
1358 1359 if(result){
  1360 + if($label.hasClass('active')){
  1361 + $label.trigger('click');
  1362 + }
  1363 +
1359 1364 jQuery.ajax({
1360 1365 type: 'GET',
1361 1366 url: url,
... ... @@ -2163,6 +2168,9 @@ jQuery(document).ready(function(){
2163 2168 $('.modal').modal('hide');
2164 2169 $('#gallery_image_' + data.id).find('.card-img-top').attr('src', data.link);
2165 2170 $('#gallery_image_' + data.id).find('.card-title').text(data.title);
  2171 + saveCurrentTags();
  2172 + $('.tags-list-block').html(data.tag_list);
  2173 + setCurrentTags();
2166 2174 }else{
2167 2175 $this.find('.error-message').html(data.message);
2168 2176 }
... ...
  1 +var currentChooseTags = [];
  2 +
  3 +var saveCurrentTags = function(){
  4 + $('.tags-list-block label.active').each(function(){
  5 + currentChooseTags.push($(this).data('value'));
  6 + });
  7 +}
  8 +
  9 +var setCurrentTags = function(){
  10 + $('.tags-list-block label').each(function(){
  11 + if(currentChooseTags.indexOf($(this).data('value')) != -1){
  12 + $(this).addClass('active');
  13 + }
  14 + });
  15 +}
  16 +
1 17 jQuery(document).ready(function(){
2   - var loadImage = function($wrapper){
  18 + var loadImage = function($wrapper, update_tag){
3 19 var url = $wrapper.data('url'),
4 20 $loader = $wrapper.find('.loader-demo'),
5 21 $images = $wrapper.find('.exist-image-list');
... ... @@ -16,11 +32,16 @@ jQuery(document).ready(function(){
16 32 type: 'POST',
17 33 url: url,
18 34 data: ({tags: mas}),
19   - dataType: 'html',
  35 + dataType: 'json',
20 36 success: function(data){
21   - $images.html(data);
  37 + $images.html(data.images);
22 38 $loader.addClass('not-visible');
23   - $images.removeClass('not-visible');
  39 + $images.removeClass('not-visible');
  40 + if(update_tag){
  41 + saveCurrentTags();
  42 + $('.tags-list-block').html(data.tag_list);
  43 + setCurrentTags();
  44 + }
24 45 }
25 46 });
26 47 };
... ... @@ -28,9 +49,9 @@ jQuery(document).ready(function(){
28 49
29 50 if($('.image-list').length > 0){
30 51 var $wrapper = $('.image-list');
31   - loadImage($wrapper);
32   - $wrapper.find('.filter label').click(function(e){
33   - if(e.target.tagName != 'A'){
  52 + loadImage($wrapper, false);
  53 + $wrapper.on('click', '.filter label', function(e){
  54 + if(e.target.tagName != 'A' && e.target.tagName != 'I'){
34 55 var $this = $(this);
35 56 if($this.hasClass('active')){
36 57 $this.removeClass('active');
... ... @@ -43,14 +64,14 @@ jQuery(document).ready(function(){
43 64 if($this.data('value') != 'all' && $this.hasClass('active')){
44 65 $wrapper.find(".filter label.active[data-value=all]").removeClass('active');
45 66 };
46   - loadImage($wrapper);
  67 + loadImage($wrapper, false);
47 68 }
48 69 });
49 70 }
50 71
51 72 $(window).bind('images:update', function(){
52 73 if($('.image-list').length > 0){
53   - loadImage($('.image-list'));
  74 + loadImage($('.image-list'), true);
54 75 };
55 76 });
56 77
... ...
... ... @@ -48,10 +48,12 @@
48 48 }
49 49
50 50 .filter .btn-group-toggle > .btn{margin-bottom:5px;position:relative;}
51   -.filter .btn-group-toggle > .btn a, .filter .btn-group-toggle > .btn a:hover{text-decoration:none;position:absolute;top:-14px;right:2px;font-size:14px;line-height:14px;}
  51 +.filter .btn-group-toggle > .btn a, .filter .btn-group-toggle > .btn a:hover{text-decoration:none;position:absolute;top:-16px;right:2px;font-size:14px;line-height:14px;}
52 52 .filter .btn-group-toggle > .btn a{display:none;}
53 53 .filter .btn-group-toggle > .btn:hover a{display:inline;}
54 54 .checkbox-list{
55 55 input{margin-right:3px;}
56 56 label{margin-right:10px;}
57   -}
\ No newline at end of file
  57 +}
  58 +
  59 +.block{display:block !important;}
\ No newline at end of file
... ...
... ... @@ -13,7 +13,7 @@ module Kanjai
13 13 collection = collection.tagged_with(params[:tags], :any => true)
14 14 end
15 15
16   - render partial: 'kanjai/admin/images/gallery_exist_images', locals: {collection: collection}
  16 + render json: {images: render_to_string(partial: 'kanjai/admin/images/gallery_exist_images', locals: {collection: collection}), tag_list: render_to_string(partial: 'kanjai/admin/images/tags')}
17 17 end
18 18
19 19 def edit
... ... @@ -34,7 +34,7 @@ module Kanjai
34 34 @file.resize!
35 35
36 36 end
37   - render json: {status: 'ok', id: @file.id, link: @file.preview_link, title: @file.title}
  37 + render json: {status: 'ok', id: @file.id, link: @file.preview_link, title: @file.title, tag_list: render_to_string(partial: 'kanjai/admin/images/tags')}
38 38 else
39 39 render json: {status: 'error', message: @file.errors.full_message}
40 40 end
... ...
... ... @@ -11,5 +11,7 @@ module Kanjai
11 11 end
12 12 render json: {status: 'ok', id: tag.id}
13 13 end
  14 +
  15 +
14 16 end
15 17 end
\ No newline at end of file
... ...
  1 +<label data-value='all' class="btn btn-primary active">All</label>
  2 +<% ActsAsTaggableOn::Tag.most_used.each do |tag| %>
  3 + <label data-value='<%= tag.name %>' class="btn btn-primary tag-item-<%= tag.id %>">
  4 + <%= tag.name %>
  5 + <a class="delete-tag-from-list" href="<%= url_for(controller: 'tags', action: 'delete', id: tag.id) %>"><i class="fa fa-trash"></i></a>
  6 + </label>
  7 +<% end %>
\ No newline at end of file
... ...
... ... @@ -32,7 +32,7 @@
32 32 <label class="col-md-2 col-form-label">Tags</label>
33 33 <div class="col-md-10">
34 34 <%= f.text_field :tag_list, class: 'form-control', data: {role: 'tagsinput'}, value: f.object.tag_list.join(', ') %>
35   - <div class="form-text"><%= t('tag_input_help_text') %></div>
  35 + <div class="invalid-feedback block"><%= t('tag_input_help_text') %></div>
36 36 </div>
37 37 </div>
38 38 </fieldset>
... ...
... ... @@ -26,14 +26,8 @@
26 26
27 27 <div class="mt-20 image-list" data-url='<%= list_admin_images_url %>'>
28 28 <div class="filter">
29   - <div class="btn-group-toggle">
30   - <label data-value='all' class="btn btn-primary active">All</label>
31   - <% ActsAsTaggableOn::Tag.most_used.each do |tag| %>
32   - <label data-value='<%= tag.name %>' class="btn btn-primary tag-item-<%= tag.id %>">
33   - <%= tag.name %>
34   - <a class="delete-tag-from-list" href="<%= url_for(controller: 'tags', action: 'delete', id: tag.id) %>"><i class="fa fa-times"></i></a>
35   - </label>
36   - <% end %>
  29 + <div class="btn-group-toggle tags-list-block">
  30 + <%= render partial: 'kanjai/admin/images/tags' %>
37 31 </div>
38 32 </div>
39 33 <div class="loader-demo">
... ...
1 1 module Kanjai
2   - VERSION = "0.0.233"
  2 + VERSION = "0.0.234"
3 3 end
... ...