|
93 | 93 | <use id="idx-nothing-found-dark" href="#nothing-found-dark"></use> |
94 | 94 | </svg> |
95 | 95 | </div> |
96 | | - <p class="no-results-title">${_lang.tplNoResultsTitle}</p> |
97 | | - <p class="no-results-text">${_lang.tplNoResultsText}</p> |
| 96 | + <p class="no-results-title" l10n>${_lang.tplNoResultsTitle}</p> |
| 97 | + <p class="no-results-text" l10n>${_lang.tplNoResultsText}</p> |
98 | 98 | </div> |
99 | 99 | <section class='themed-sroll' panel='all'> |
100 | 100 | <div class='table-box flex-fill'> |
|
146 | 146 | }); |
147 | 147 |
|
148 | 148 | utils.fn.extend(ControllerTemplates.prototype, (function() { |
149 | | - let _page_num = 0, |
150 | | - isLoading = false, |
151 | | - totalPages = null; |
| 149 | + let isCloudTmplsLoading = false; |
152 | 150 |
|
153 | 151 | const _on_nav_item_click = function(e) { |
154 | 152 | $('.nav-item', this.view.$panel).removeClass('selected'); |
|
353 | 351 | $('#search-no-results', $panel).toggle(matchCount === 0); |
354 | 352 | }; |
355 | 353 |
|
356 | | - const _loadTemplates = function() { |
357 | | - if (isLoading || (totalPages !== null && _page_num >= totalPages)) return; |
| 354 | + const _loadTemplates = function(nl, page_num = 0) { |
| 355 | + const locale = nl ? nl.split('_')[0].toLowerCase() : 'en'; |
| 356 | + if (isCloudTmplsLoading) return; |
358 | 357 |
|
359 | | - _page_num++; |
360 | | - isLoading = true; |
| 358 | + page_num++; |
| 359 | + isCloudTmplsLoading = true; |
361 | 360 |
|
362 | 361 | const _domain = localStorage.templatesdomain ? localStorage.templatesdomain : 'https://oforms.onlyoffice.com'; // https://oforms.teamlab.info |
363 | | - const _url = `${_domain}/dashboard/api/oforms?populate=*&locale=en&pagination[page]=${_page_num}`; |
| 362 | + const _url = `${_domain}/dashboard/api/oforms?populate=*&locale=${locale}&pagination[page]=${page_num}`; |
364 | 363 | fetch(_url) |
365 | 364 | .then(r => r.json()) |
366 | 365 | .then(d => { |
367 | | - isLoading = false; |
368 | | - if (d.data) { |
| 366 | + isCloudTmplsLoading = false; |
| 367 | + if (d.data && d.data.length > 0) { |
369 | 368 | _on_add_cloud_templates.call(this, d.data); |
370 | | - totalPages = d.meta.pagination.pageCount; |
| 369 | + const totalPages = d.meta.pagination.pageCount; |
371 | 370 |
|
372 | | - if (_page_num < totalPages) { |
373 | | - _loadTemplates.call(this); |
| 371 | + if (page_num + 1 <= totalPages) { |
| 372 | + _loadTemplates.call(this, nl, page_num); |
374 | 373 | } |
375 | | - } |
| 374 | + } else if (d.data && d.data.length === 0 && locale !== 'en') { |
| 375 | + _resetPagination.call(this); |
| 376 | + _loadTemplates.call(this, 'en', 0); |
| 377 | + } |
376 | 378 | }) |
377 | 379 | .catch (function (err) { |
378 | 380 | console.error(err); |
|
382 | 384 | }) |
383 | 385 | }; |
384 | 386 |
|
385 | | - const loadAllPages = function() { |
386 | | - if (isLoading) return; |
387 | | - |
388 | | - _page_num = 0; |
389 | | - const self = this; |
390 | | - const loadNext = () => { |
391 | | - if (_page_num < totalPages || totalPages === null) { |
392 | | - _loadTemplates.call(self); |
393 | | - setTimeout(loadNext, 150); |
394 | | - } |
395 | | - }; |
396 | | - |
397 | | - loadNext(); |
| 387 | + const _resetPagination = function() { |
| 388 | + isCloudTmplsLoading = false; |
| 389 | + this.templates.empty(); |
398 | 390 | }; |
399 | 391 |
|
400 | 392 | return { |
|
438 | 430 | ls.push("en-US","en_US","en"); |
439 | 431 | window.sdk.LocalFileTemplates(ls); |
440 | 432 | }; |
441 | | - _reload_templates(utils.Lang.id); |
442 | 433 |
|
443 | 434 | CommonEvents.on('lang:changed', (ol, nl) => { |
| 435 | + _resetPagination.call(this); |
444 | 436 | _reload_templates(nl); |
| 437 | + _loadTemplates.call(this, nl); |
| 438 | + $('#template-search', this.view.$panel).attr('placeholder', utils.Lang.tplSearch); |
445 | 439 | }); |
446 | 440 |
|
447 | | - loadAllPages.call(this); |
| 441 | + _reload_templates(utils.Lang.id); |
| 442 | + _loadTemplates.call(this, utils.Lang.id); |
448 | 443 |
|
449 | 444 | return this; |
450 | 445 | } |
|
0 commit comments