Commit 722860b0a5b51c2fdc0884d0a5f69f5284f6cd05

Authored by Karpikau Andrei
1 parent 65f72ad7

check bugs about update file and tags

... ... @@ -1602,16 +1602,40 @@ var clearAjaxFileUpload = function(selector){
1602 1602 selector.find('.ajax-file-upload-form').unbind('submit');
1603 1603 };
1604 1604
  1605 +var loadTags = function(callback){
  1606 + $.get('/admin/tags', {}, function(data){
  1607 + callback(data);
  1608 + });
  1609 +}
  1610 +
  1611 +
  1612 +var substringMatcher = function(strs) {
  1613 + return function findMatches(q, cb) {
  1614 + var matches, substringRegex;
  1615 +
  1616 + // an array that will be populated with substring matches
  1617 + matches = [];
  1618 +
  1619 + // regex used to determine if a string contains the substring `q`
  1620 + var substrRegex = new RegExp(q, 'i');
  1621 +
  1622 + // iterate through the pool of strings and for any string that
  1623 + // contains the substring `q`, add it to the `matches` array
  1624 + $.each(strs, function(i, str) {
  1625 + if (substrRegex.test(str.title)) {
  1626 + matches.push(str);
  1627 + }
  1628 + });
  1629 + cb(matches);
  1630 + };
  1631 +};
  1632 +
1605 1633
1606 1634 var tagnames = new Bloodhound({
1607 1635 datumTokenizer: Bloodhound.tokenizers.obj.whitespace('title'),
1608 1636 queryTokenizer: Bloodhound.tokenizers.whitespace,
1609 1637 prefetch: {
1610   - url: '/admin/tags',
1611   - filter: function(list) {
1612   - return $.map(list, function(title) {
1613   - return { title: title }; });
1614   - }
  1638 + url: '/admin/tags'
1615 1639 }
1616 1640 });
1617 1641 tagnames.initialize();
... ... @@ -1947,14 +1971,24 @@ jQuery(document).ready(function(){
1947 1971
1948 1972
1949 1973
1950   - $template.find("input[data-role=tagsinput]").tagsinput({
1951   - typeaheadjs: {
1952   - name: 'title',
1953   - displayKey: 'title',
1954   - valueKey: 'title',
1955   - source: tagnames.ttAdapter()
1956   - }
  1974 +
  1975 +
  1976 + if($template.find("input[data-role=tagsinput]").length > 0){
  1977 + loadTags(function(data){
  1978 + $template.find("input[data-role=tagsinput]").tagsinput({
  1979 + typeaheadjs: {
  1980 + name: 'title',
  1981 + minLength: 0,
  1982 + displayKey: 'title',
  1983 + valueKey: 'title',
  1984 + source: substringMatcher(data),
  1985 + limit: 1000
  1986 + },
  1987 + maxChars: 0
  1988 + });
1957 1989 });
  1990 + }
  1991 +
1958 1992 }else{
1959 1993 $('#gallery_form form #new_images').append($fileInput);
1960 1994 }
... ... @@ -2049,14 +2083,25 @@ jQuery(document).ready(function(){
2049 2083
2050 2084 var $modal = $data.modal({show: false, keyboard: false, backdrop: 'static'}).on('shown.bs.modal', function (e) {
2051 2085 var $this = $(this);
2052   - $this.find("input[data-role=tagsinput]").tagsinput({
2053   - typeaheadjs: {
2054   - name: 'title',
2055   - displayKey: 'title',
2056   - valueKey: 'title',
2057   - source: tagnames.ttAdapter()
2058   - }
2059   - });
  2086 +
  2087 +
  2088 + if($this.find("input[data-role=tagsinput]").length > 0){
  2089 + loadTags(function(data){
  2090 + $this.find("input[data-role=tagsinput]").tagsinput({
  2091 + typeaheadjs: {
  2092 + name: 'title',
  2093 + minLength: 0,
  2094 + displayKey: 'title',
  2095 + valueKey: 'title',
  2096 + source: substringMatcher(data),
  2097 + limit: 1000
  2098 + },
  2099 + maxChars: 0
  2100 + });
  2101 + });
  2102 + }
  2103 +
  2104 +
2060 2105 $this.find('.filestyle').each(function() {
2061 2106 var $this = $(this), options = {
2062 2107 'input' : $this.attr('data-input') !== 'false',
... ... @@ -2086,6 +2131,7 @@ jQuery(document).ready(function(){
2086 2131 if(data.status == 'ok'){
2087 2132 $('.modal').modal('hide');
2088 2133 $('#gallery_image_' + data.id).find('.card-img-top').attr('src', data.link);
  2134 + $('#gallery_image_' + data.id).find('.card-title').text(data.title);
2089 2135 }else{
2090 2136 $this.find('.error-message').html(data.message);
2091 2137 }
... ...
... ... @@ -2081,6 +2081,7 @@
2081 2081 this.isActive() && this.open();
2082 2082 },
2083 2083 _minLengthMet: function minLengthMet(query) {
  2084 + return true;
2084 2085 query = _.isString(query) ? query : this.input.getQuery() || "";
2085 2086 return query.length >= this.minLength;
2086 2087 },
... ...
... ... @@ -38,6 +38,11 @@
38 38 padding-left:20px;
39 39 }
40 40
  41 +.tt-dataset{
  42 + max-height: 200px;
  43 + overflow-y: scroll;
  44 +}
  45 +
41 46 .gray-theme.fr-toolbar .fr-command.fr-btn.fr-disabled, .gray-theme.fr-popup .fr-command.fr-btn.fr-disabled{
42 47
43 48 }
\ No newline at end of file
... ...
... ... @@ -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}
  37 + render json: {status: 'ok', id: @file.id, link: @file.preview_link, title: @file.title}
38 38 else
39 39 render json: {status: 'error', message: @file.errors.full_message}
40 40 end
... ...
1 1 module Kanjai
2 2 class Admin::TagsController < AdminController
3 3 def index
4   - render json: ActsAsTaggableOn::Tag.order(:name).pluck(:name)
  4 + render json: ActsAsTaggableOn::Tag.order(:name).collect{|item| {title: item.name}}
5 5 end
6 6 end
7 7 end
\ No newline at end of file
... ...
... ... @@ -31,7 +31,7 @@
31 31 <div class="form-group row">
32 32 <label class="col-md-2 col-form-label">Tags</label>
33 33 <div class="col-md-10">
34   - <%= f.text_field :tag_list, class: 'form-control', data: {role: 'tagsinput'} %>
  34 + <%= f.text_field :tag_list, class: 'form-control', data: {role: 'tagsinput'}, value: f.object.tag_list.join(', ') %>
35 35 </div>
36 36 </div>
37 37 </fieldset>
... ...
... ... @@ -26,7 +26,7 @@
26 26 </div>
27 27 </div>
28 28 <div class="card-body">
29   - <div class="table-responsive">
  29 + <div class="">
30 30 <div class="nestable-page-list dd dd-full-width page-list">
31 31 <ol class="dd-list">
32 32 <%= render partial: 'kanjai/admin/pages/page_block', locals: {collection: domain.pages.where(parent: nil).order(:position)} %>
... ...
1 1 module Kanjai
2   - VERSION = "0.0.230"
  2 + VERSION = "0.0.231"
3 3 end
... ...