Перейти к содержимому


Фотография
- - - - -

Автоматическая генерация названий


Лучший Ответ Cheren-dow , 18 January 2016 - 14:19

Iv_Le сказал(а) 14 Янв 2016 - 23:48:

Русские названия генерирует без пробела

Здравствуйте, Замените код в файле:

  1. \media\zoo\applications\jbuniversal\templates\auto\assets\js\widget\namecreator.js

на:

  1. /**
  2. * JBZoo App is universal Joomla CCK, application for YooTheme Zoo component
  3. *
  4. * @package jbzoo
  5. * @version 2.x Pro
  6. * @author JBZoo App http://jbzoo.com
  7. * @copyright Copyright (C) JBZoo.com, All rights reserved.
  8. * @license http://jbzoo.com/license-pro.php JBZoo Licence
  9. * @coder Sergey Kalistratov <kalistratov.s.m@jgmail.com>
  10. */
  11.  
  12. ;
  13. (function ($, window, document, undefined) {
  14.  
  15. /**
  16. * NameCreator widget
  17. */
  18. JBZoo.widget('JBZoo.NameCreator', {
  19. 'elResYear' : '.jsNameYear',
  20. 'elResColor' : '.jsNameColor',
  21. 'elRestCity' : '.jsNameCity',
  22. 'elRestCat' : '.jsNameCat',
  23. 'elCity' : '#elements66f74b23-cd70-4f76-8a7e-a24412fad598option',
  24. 'elYear' : 'f83cbbe4-bb47-46f0-81cd-b885ae7a388e',
  25. 'elColor' : 'b8b4f50f-34ab-49f3-a56f-0e684d72a2f2',
  26. 'elCategory' : '#elements_itemcategoryvalue',
  27. 'elName' : '_itemname'
  28. }, {
  29.  
  30. init : function($this){
  31. $this.setupName($this);
  32. },
  33.  
  34. /**
  35. * Setup name on submit form.
  36. *
  37. * @param $this
  38. */
  39. setupName : function($this) {
  40. $this.$('#submit-button').on('click', function (e) {
  41. $this._processCity($this);
  42. $this._processYear($this);
  43. $this._processColor($this);
  44. $this._processCategories($this);
  45.  
  46. var itemName, category, color, year, city;
  47.  
  48. category = $($this.options.elRestCat).text();
  49. year = $($this.options.elResYear).text();
  50. color = $($this.options.elResColor).text();
  51. city = $($this.options.elRestCity).text();
  52.  
  53. itemName = category + color + year + city;
  54.  
  55. $('input[name*=' + $this.options.elName + ']').attr('value', itemName);
  56.  
  57. setTimeout(function () {
  58. document.submissionForm.submit();
  59. }, 200);
  60.  
  61. e.preventDefault();
  62. });
  63. },
  64.  
  65. /**
  66. * Find and set city value.
  67. *
  68. * @param $this
  69. * @private
  70. */
  71. _processCity : function ($this) {
  72. var city = $this.$($this.options.elCity + ' option:selected').text();
  73.  
  74. // Write city selected value.
  75. $($this.options.elRestCity).text(city);
  76. },
  77.  
  78. /**
  79. * Find and ser color value.
  80. *
  81. * @param $this
  82. * @private
  83. */
  84. _processColor : function ($this) {
  85. var queryColor = 'input[name*=' + $this.options.elColor + ']';
  86. var color = $this.$(queryColor + ':checked').val();
  87.  
  88. // Write color selected value.
  89. if (color) {
  90. $($this.options.elResColor).text(' (' + color + ')');
  91. }
  92. },
  93.  
  94. /**
  95. * Find and set year.
  96. *
  97. * @param $this
  98. * @private
  99. */
  100. _processYear : function ($this) {
  101. // Write year value.
  102. $($this.options.elResYear).text(' - ' + $this.$('input[name*=' + $this.options.elYear + ']').val() + ', ');
  103. },
  104.  
  105. /**
  106. * Find and set category values.
  107. *
  108. * @param $this
  109. * @private
  110. */
  111. _processCategories : function ($this) {
  112. var categoryName = '';
  113.  
  114. $this.$($this.options.elCategory+ ' option:selected').each(function (index, value) {
  115.  
  116. categoryName = categoryName + $this._clearStr($(this).html());
  117.  
  118. if (index == 0) {
  119. categoryName = categoryName + ' / ';
  120. }
  121.  
  122. });
  123.  
  124. $($this.options.elRestCat).text(categoryName);
  125. },
  126.  
  127. /**
  128. * Clear string.
  129. *
  130. * @param str
  131. * @returns {*}
  132. * @private
  133. */
  134. _clearStr : function (str) {
  135. return str.replace(/(&nbsp;|\.&nbsp;|-&nbsp;)/g, '');
  136. }
  137.  
  138. });
  139.  
  140. })(jQuery, window, document);
  141.  

Iv_Le сказал(а) 15 Янв 2016 - 10:00:

И все-таки у меня не получается задать свои элементы формы, которые бы участвовали в автособирании названия. Если я подставлю ID элемента вместо elYear, то нормально. Но если я создаю свое, то не получамба. 

Новый метод который вы сделали по аналогу  _processYear добавьте в метод setupName, что бы он вызывался. В вашем случае необходимо добавить:

  1. $this._processSn($this);
Перейти к сообщению


  • Закрытая тема Тема закрыта
Сообщений в теме: 8

#1 Хозяин Морей

Хозяин Морей

Отправлено 09 December 2015 - 14:35

На вашем новом демо-сайте автомобильной тематики использована форма для создания объявления с  автоматической генерацией имен.

 

А где можно узнать, как генерируются имена, если надо, чтоб названия формировались сами из других полей? И если на сайте разные типы материалов, то чтоб у каждого формировалось по своему.


  • 0

#2 Cheren-dow

Cheren-dow

Отправлено 09 December 2015 - 21:53

Хозяин Морей, здравствуйте, генерация происходит с помощью JS скрипта который расположен по пути:

  1. \media\zoo\applications\jbuniversal\templates\auto\assets\js\widget\namecreator.js

По клику на кнопку отправки формы берется значения из указанных в JS элементов формы.

Хозяин Морей сказал(а) 09 Дек 2015 - 13:35:

И если на сайте разные типы материалов, то чтоб у каждого формировалось по своему.

В том случае нужно создавать несколько дублей JS файлов и подключать их в зависимости от типа в файле:

  1. \media\zoo\applications\jbuniversal\templates\auto\_submission.php

Например делать проверку на ID типа, получить id типа можно с помощью:

  1. $this->type->id

Или же по псевдониму типа:

  1. $this->item->type

  • 2
Изображение
 

#3 Iv_Le

Iv_Le

Отправлено 15 January 2016 - 00:48

Русские названия генерирует без пробела

 

 

6wVwQDo7.png


  • 0

#4 Cheren-dow

Cheren-dow

Отправлено 15 January 2016 - 08:22

Iv_Le, можете дать ссылку на сайт? 


  • 0
Изображение
 

#5 Iv_Le

Iv_Le

Отправлено 15 January 2016 - 11:00

Отправил ЛС.

 

И все-таки у меня не получается задать свои элементы формы, которые бы участвовали в автособирании названия. Если я подставлю ID элемента вместо elYear, то нормально. Но если я создаю свое, то не получамба. 

  1. /**
  2. * JBZoo App is universal Joomla CCK, application for YooTheme Zoo component
  3. *
  4. * @package jbzoo
  5. * @version 2.x Pro
  6. * @author JBZoo App http://jbzoo.com
  7. * @copyright Copyright (C) JBZoo.com, All rights reserved.
  8. * @license http://jbzoo.com/license-pro.php JBZoo Licence
  9. * @coder Sergey Kalistratov <kalistratov.s.m@jgmail.com>
  10. */
  11.  
  12. ;
  13. (function ($, window, document, undefined) {
  14.  
  15. /**
  16. * NameCreator widget
  17. */
  18. JBZoo.widget('JBZoo.NameCreator', {
  19. 'elResYear' : '.jsNameYear',
  20. 'elResColor' : '.jsNameColor',
  21. 'elRestCity' : '.jsNameCity',
  22. 'elRestCat' : '.jsNameCat',
  23. 'elRestSn' : '.jsNameSn',
  24. 'elCity' : '#elements66f74b23-cd70-4f76-8a7e-a24412fad598option',
  25. 'elYear' : 'f83cbbe4-bb47-46f0-81cd-b885ae7a388e',
  26. 'elColor' : 'b8b4f50f-34ab-49f3-a56f-0e684d72a2f2',
  27. 'elCategory' : '#elements_itemcategoryvalue',
  28. 'elName' : '_itemname',
  29. 'elSn' : '7fe518d8-5517-4a1f-abc0-30f8d0cb5786'
  30. }, {
  31.  
  32. init : function($this){
  33. $this.setupName($this);
  34. },
  35.  
  36. /**
  37. * Setup name on submit form.
  38. *
  39. * @param $this
  40. */
  41. setupName : function($this) {
  42. $this.$('#submit-button').on('click', function (e) {
  43. $this._processCity($this);
  44. $this._processYear($this);
  45. $this._processColor($this);
  46. $this._processCategories($this);
  47. $this._processSn($this);
  48.  
  49. var itemName, category, color, year, city, sn;
  50.  
  51. category = $($this.options.elRestCat).text();
  52. year = $($this.options.elResYear).text();
  53. color = $($this.options.elResColor).text();
  54. city = $($this.options.elRestCity).text();
  55. sn = $($this.options.elRestSn).text();
  56.  
  57. itemName = category + sn + color + year + city;
  58.  
  59. $('input[name*=' + $this.options.elName + ']').attr('value', itemName);
  60.  
  61. setTimeout(function () {
  62. document.submissionForm.submit();
  63. }), 200;
  64.  
  65. e.preventDefault();
  66. });
  67. },
  68.  
  69. /**
  70. * Find and set city value.
  71. *
  72. * @param $this
  73. * @private
  74. */
  75. _processCity : function ($this) {
  76. var city = $this.$($this.options.elCity + ' option:selected').text();
  77.  
  78. // Write city selected value.
  79. $($this.options.elRestCity).text(city);
  80. },
  81.  
  82. /**
  83. * Find and ser color value.
  84. *
  85. * @param $this
  86. * @private
  87. */
  88. _processColor : function ($this) {
  89. var queryColor = 'input[name*=' + $this.options.elColor + ']';
  90. var color = $this.$(queryColor + ':checked').val();
  91.  
  92. // Write color selected value.
  93. if (color) {
  94. $($this.options.elResColor).text(' (' + color + ')');
  95. }
  96. },
  97.  
  98. /**
  99. * Find and set year.
  100. *
  101. * @param $this
  102. * @private
  103. */
  104. _processYear : function ($this) {
  105. // Write year value.
  106. $($this.options.elResYear).text(' - ' + $this.$('input[name*=' + $this.options.elYear + ']').val() + ', ');
  107. },
  108. /**
  109. * Find and set year.
  110. *
  111. * @param $this
  112. * @private
  113. */
  114. _processSn : function ($this) {
  115. // Write year value.
  116. $($this.options.elRestSn).text(' - ' + $this.$('input[name*=' + $this.options.elSn + ']').val() + ', ');
  117. },
  118. /**
  119. * Find and set category values.
  120. *
  121. * @param $this
  122. * @private
  123. */
  124. _processCategories : function ($this) {
  125. var categoryName = '';
  126.  
  127. $this.$($this.options.elCategory+ ' option:selected').each(function (index, value) {
  128.  
  129. categoryName = categoryName + $this._clearStr($(this).text());
  130.  
  131. if (index == 0) {
  132. categoryName = categoryName + ' / ';
  133. }
  134.  
  135. });
  136.  
  137. $($this.options.elRestCat).text(categoryName);
  138. },
  139.  
  140. /**
  141. * Clear string.
  142. *
  143. * @param str
  144. * @returns {*}
  145. * @private
  146. */
  147. _clearStr : function (str) {
  148. return str.replace(/[^а-яА-ЯёЁa-zA-Z0-9]/g, '');
  149. }
  150.  
  151. });
  152.  
  153. })(jQuery, window, document);
  154.  

Кроме того, заполнил файл jbads.php и не катит. Шо я не понял?

Эту тему прочитал


  • 0

#6 Cheren-dow

Cheren-dow

Отправлено 18 January 2016 - 14:19   Лучший Ответ

Iv_Le сказал(а) 14 Янв 2016 - 23:48:

Русские названия генерирует без пробела

Здравствуйте, Замените код в файле:

  1. \media\zoo\applications\jbuniversal\templates\auto\assets\js\widget\namecreator.js

на:

  1. /**
  2. * JBZoo App is universal Joomla CCK, application for YooTheme Zoo component
  3. *
  4. * @package jbzoo
  5. * @version 2.x Pro
  6. * @author JBZoo App http://jbzoo.com
  7. * @copyright Copyright (C) JBZoo.com, All rights reserved.
  8. * @license http://jbzoo.com/license-pro.php JBZoo Licence
  9. * @coder Sergey Kalistratov <kalistratov.s.m@jgmail.com>
  10. */
  11.  
  12. ;
  13. (function ($, window, document, undefined) {
  14.  
  15. /**
  16. * NameCreator widget
  17. */
  18. JBZoo.widget('JBZoo.NameCreator', {
  19. 'elResYear' : '.jsNameYear',
  20. 'elResColor' : '.jsNameColor',
  21. 'elRestCity' : '.jsNameCity',
  22. 'elRestCat' : '.jsNameCat',
  23. 'elCity' : '#elements66f74b23-cd70-4f76-8a7e-a24412fad598option',
  24. 'elYear' : 'f83cbbe4-bb47-46f0-81cd-b885ae7a388e',
  25. 'elColor' : 'b8b4f50f-34ab-49f3-a56f-0e684d72a2f2',
  26. 'elCategory' : '#elements_itemcategoryvalue',
  27. 'elName' : '_itemname'
  28. }, {
  29.  
  30. init : function($this){
  31. $this.setupName($this);
  32. },
  33.  
  34. /**
  35. * Setup name on submit form.
  36. *
  37. * @param $this
  38. */
  39. setupName : function($this) {
  40. $this.$('#submit-button').on('click', function (e) {
  41. $this._processCity($this);
  42. $this._processYear($this);
  43. $this._processColor($this);
  44. $this._processCategories($this);
  45.  
  46. var itemName, category, color, year, city;
  47.  
  48. category = $($this.options.elRestCat).text();
  49. year = $($this.options.elResYear).text();
  50. color = $($this.options.elResColor).text();
  51. city = $($this.options.elRestCity).text();
  52.  
  53. itemName = category + color + year + city;
  54.  
  55. $('input[name*=' + $this.options.elName + ']').attr('value', itemName);
  56.  
  57. setTimeout(function () {
  58. document.submissionForm.submit();
  59. }, 200);
  60.  
  61. e.preventDefault();
  62. });
  63. },
  64.  
  65. /**
  66. * Find and set city value.
  67. *
  68. * @param $this
  69. * @private
  70. */
  71. _processCity : function ($this) {
  72. var city = $this.$($this.options.elCity + ' option:selected').text();
  73.  
  74. // Write city selected value.
  75. $($this.options.elRestCity).text(city);
  76. },
  77.  
  78. /**
  79. * Find and ser color value.
  80. *
  81. * @param $this
  82. * @private
  83. */
  84. _processColor : function ($this) {
  85. var queryColor = 'input[name*=' + $this.options.elColor + ']';
  86. var color = $this.$(queryColor + ':checked').val();
  87.  
  88. // Write color selected value.
  89. if (color) {
  90. $($this.options.elResColor).text(' (' + color + ')');
  91. }
  92. },
  93.  
  94. /**
  95. * Find and set year.
  96. *
  97. * @param $this
  98. * @private
  99. */
  100. _processYear : function ($this) {
  101. // Write year value.
  102. $($this.options.elResYear).text(' - ' + $this.$('input[name*=' + $this.options.elYear + ']').val() + ', ');
  103. },
  104.  
  105. /**
  106. * Find and set category values.
  107. *
  108. * @param $this
  109. * @private
  110. */
  111. _processCategories : function ($this) {
  112. var categoryName = '';
  113.  
  114. $this.$($this.options.elCategory+ ' option:selected').each(function (index, value) {
  115.  
  116. categoryName = categoryName + $this._clearStr($(this).html());
  117.  
  118. if (index == 0) {
  119. categoryName = categoryName + ' / ';
  120. }
  121.  
  122. });
  123.  
  124. $($this.options.elRestCat).text(categoryName);
  125. },
  126.  
  127. /**
  128. * Clear string.
  129. *
  130. * @param str
  131. * @returns {*}
  132. * @private
  133. */
  134. _clearStr : function (str) {
  135. return str.replace(/(&nbsp;|\.&nbsp;|-&nbsp;)/g, '');
  136. }
  137.  
  138. });
  139.  
  140. })(jQuery, window, document);
  141.  

Iv_Le сказал(а) 15 Янв 2016 - 10:00:

И все-таки у меня не получается задать свои элементы формы, которые бы участвовали в автособирании названия. Если я подставлю ID элемента вместо elYear, то нормально. Но если я создаю свое, то не получамба. 

Новый метод который вы сделали по аналогу  _processYear добавьте в метод setupName, что бы он вызывался. В вашем случае необходимо добавить:

  1. $this._processSn($this);

  • 2
Изображение
 

#7 Iv_Le

Iv_Le

Отправлено 18 January 2016 - 17:47

Спасибо. А в чем трабл был? Я про русские слова.


Сообщение отредактировал Iv_Le: 18 January 2016 - 17:48

  • 0

#8 Cheren-dow

Cheren-dow

Отправлено 18 January 2016 - 19:46

Iv_Le, регулярное выражение в JS жестко вырезала все символы и оставляло только кириллицу и латиницу. Вопрос можно считать решенным, закрываем топик? 


  • 0
Изображение
 

#9 Iv_Le

Iv_Le

Отправлено 18 January 2016 - 19:49

Я бы предложил так: топик этот закрыть, НО, по отдельно по каждому шаблону создать отдельную тему незакрываемую, где бы копились вопросы и ответы.

 

Поздравляю с некурением 787 дней.


Сообщение отредактировал Iv_Le: 18 January 2016 - 19:51

  • 1




Click to return to top of page in style!