[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 /* 2 YUI 3.17.2 (build 9c3c78e) 3 Copyright 2014 Yahoo! Inc. All rights reserved. 4 Licensed under the BSD License. 5 http://yuilibrary.com/license/ 6 */ 7 8 YUI.add('datatable-paginator', function (Y, NAME) { 9 10 /** 11 Adds support for paging through data in the DataTable. 12 13 @module datatable 14 @submodule datatable-paginator 15 @since 3.11.0 16 */ 17 18 var Model, 19 View, 20 PaginatorTemplates = Y.DataTable.Templates.Paginator, 21 sub = Y.Lang.sub, 22 getClassName = Y.ClassNameManager.getClassName, 23 CLASS_DISABLED = getClassName(NAME, 'control-disabled'), 24 EVENT_UI = 'paginator:ui'; 25 26 27 /** 28 @class DataTable.Paginator.Model 29 @extends Model 30 @since 3.11.0 31 */ 32 Model = Y.Base.create('dt-pg-model', Y.Model, [Y.Paginator.Core]), 33 34 /** 35 @class DataTable.Paginator.View 36 @extends View 37 @since 3.11.0 38 */ 39 View = Y.Base.create('dt-pg-view', Y.View, [], { 40 /** 41 Array of event handles to keep track of what should be destroyed later 42 @protected 43 @property _eventHandles 44 @type {Array} 45 @since 3.11.0 46 */ 47 _eventHandles: [], 48 49 /** 50 Template for this view's container. 51 @property containerTemplate 52 @type {String} 53 @default '<div class="yui3-datatable-paginator"/>' 54 @since 3.11.0 55 */ 56 containerTemplate: '<div class="{paginator}"/>', 57 58 /** 59 Template for content. Helps maintain order of controls. 60 @property contentTemplate 61 @type {String} 62 @default '{buttons}{goto}{perPage}' 63 @since 3.11.0 64 */ 65 contentTemplate: '{buttons}{goto}{perPage}', 66 67 /** 68 Disables ad-hoc ATTRS for our view. 69 @protected 70 @property _allowAdHocAttrs 71 @type {Boolean} 72 @default false 73 @since 3.11.0 74 */ 75 _allowAdHocAttrs: false, 76 77 /** 78 Sets classnames on the templates and bind events 79 @method initializer 80 @since 3.11.0 81 */ 82 initializer: function () { 83 this.containerTemplate = sub(this.containerTemplate, { 84 paginator: getClassName(NAME) 85 }); 86 87 this._initStrings(); 88 this._initClassNames(); 89 90 this.attachEvents(); 91 }, 92 93 /** 94 @method render 95 @chainable 96 @since 3.11.0 97 */ 98 render: function () { 99 var model = this.get('model'), 100 content = sub(this.contentTemplate, { 101 'buttons': this._buildButtonsGroup(), 102 'goto': this._buildGotoGroup(), 103 'perPage': this._buildPerPageGroup() 104 }); 105 106 this.get('container').append(content); 107 this.attachEvents(); 108 109 this._rendered = true; 110 111 this._updateControlsUI(model.get('page')); 112 this._updateItemsPerPageUI(model.get('itemsPerPage')); 113 114 return this; 115 }, 116 117 /** 118 @method attachEvents 119 @since 3.11.0 120 */ 121 attachEvents: function () { 122 View.superclass.attachEvents.apply(this, arguments); 123 124 var container = this.get('container'); 125 126 if (!this.classNames) { 127 this._initClassNames(); 128 } 129 130 this._attachedViewEvents.push( 131 container.delegate('click', this._controlClick, '.' + this.classNames.control, this), 132 this.get('model').after('change', this._modelChange, this) 133 ); 134 135 container.all('form').each(Y.bind(function (frm) { 136 this._attachedViewEvents.push( 137 frm.after('submit', this._controlSubmit, this) 138 ); 139 }, this)); 140 141 container.all('select').each(Y.bind(function (sel) { 142 this._attachedViewEvents.push( 143 sel.after('change', this._controlChange, this) 144 ); 145 }, this)); 146 147 }, 148 149 /** 150 Returns a string built from the button and buttons templates. 151 @protected 152 @method _buildButtonsGroup 153 @return {String} 154 @since 3.11.0 155 */ 156 _buildButtonsGroup: function () { 157 var strings = this.get('strings'), 158 classNames = this.classNames, 159 buttons; 160 161 buttons = PaginatorTemplates.button({ 162 type: 'first', label: strings.first, classNames: classNames 163 }) + 164 PaginatorTemplates.button({ 165 type: 'prev', label: strings.prev, classNames: classNames 166 }) + 167 PaginatorTemplates.button({ 168 type: 'next', label: strings.next, classNames: classNames 169 }) + 170 PaginatorTemplates.button({ 171 type: 'last', label: strings.last, classNames: classNames 172 }); 173 174 return PaginatorTemplates.buttons({ 175 classNames: classNames, 176 buttons: buttons 177 }); 178 179 }, 180 181 /** 182 Returns a string built from the gotoPage template. 183 @protected 184 @method _buildGotoGroup 185 @return {String} 186 @since 3.11.0 187 */ 188 _buildGotoGroup: function () { 189 190 return PaginatorTemplates.gotoPage({ 191 classNames: this.classNames, 192 strings: this.get('strings'), 193 page: this.get('model').get('page') 194 }); 195 }, 196 197 /** 198 Returns a string built from the perPage template 199 @protected 200 @method _buildPerPageGroup 201 @return {String} 202 @since 3.11.0 203 */ 204 _buildPerPageGroup: function () { 205 var options = this.get('pageSizes'), 206 rowsPerPage = this.get('model').get('rowsPerPage'), 207 option, 208 len, 209 i; 210 211 for (i = 0, len = options.length; i < len; i++ ) { 212 option = options[i]; 213 214 if (typeof option !== 'object') { 215 option = { 216 value: option, 217 label: option 218 }; 219 } 220 option.selected = (option.value === rowsPerPage) ? ' selected' : ''; 221 } 222 223 return PaginatorTemplates.perPage({ 224 classNames: this.classNames, 225 strings: this.get('strings'), 226 options: this.get('pageSizes') 227 }); 228 229 }, 230 231 /** 232 Update the UI after the model has changed. 233 @protected 234 @method _modelChange 235 @param {EventFacade} e 236 @since 3.11.0 237 */ 238 _modelChange: function (e) { 239 var changed = e.changed, 240 page = (changed && changed.page), 241 itemsPerPage = (changed && changed.itemsPerPage); 242 243 if (page) { 244 this._updateControlsUI(page.newVal); 245 } 246 if (itemsPerPage) { 247 this._updateItemsPerPageUI(itemsPerPage.newVal); 248 if (!page) { 249 this._updateControlsUI(e.target.get('page')); 250 } 251 } 252 253 }, 254 255 /** 256 Updates the button controls and the gotoPage form 257 @protected 258 @method _updateControlsUI 259 @param {Number} val Page number to set the UI input to 260 @since 3.11.0 261 */ 262 _updateControlsUI: function (val) { 263 if (!this._rendered) { 264 return; 265 } 266 267 var model = this.get('model'), 268 controlClass = '.' + this.classNames.control, 269 container = this.get('container'), 270 hasPrev = model.hasPrevPage(), 271 hasNext = model.hasNextPage(); 272 273 container.one(controlClass + '-first') 274 .toggleClass(CLASS_DISABLED, !hasPrev) 275 .set('disabled', !hasPrev); 276 277 container.one(controlClass + '-prev') 278 .toggleClass(CLASS_DISABLED, !hasPrev) 279 .set('disabled', !hasPrev); 280 281 container.one(controlClass + '-next') 282 .toggleClass(CLASS_DISABLED, !hasNext) 283 .set('disabled', !hasNext); 284 285 container.one(controlClass + '-last') 286 .toggleClass(CLASS_DISABLED, !hasNext) 287 .set('disabled', !hasNext); 288 289 container.one('form input').set('value', val); 290 }, 291 292 /** 293 Updates the drop down select for items per page 294 @protected 295 @method _updateItemsPerPageUI 296 @param {Number} val Number of items to display per page 297 @since 3.11.0 298 */ 299 _updateItemsPerPageUI: function (val) { 300 if (!this._rendered) { 301 return; 302 } 303 304 this.get('container').one('select').set('value', val); 305 }, 306 307 /** 308 Fire EVENT_UI when an enabled control button is clicked 309 @protected 310 @method _controlClick 311 @param {EventFacade} e 312 @since 3.11.0 313 */ 314 _controlClick: function (e) { // buttons 315 e.preventDefault(); 316 var control = e.currentTarget; 317 // register click events from the four control buttons 318 if (control.hasClass(CLASS_DISABLED)) { 319 return; 320 } 321 this.fire(EVENT_UI, { 322 type: control.getData('type'), 323 val: control.getData('page') || null 324 }); 325 }, 326 327 /** 328 Fire EVENT_UI with `type:perPage` after the select drop down changes 329 @protected 330 @method _controlChange 331 @param {EventFacade} e 332 @since 3.11.0 333 */ 334 _controlChange: function (e) { 335 336 // register change events from the perPage select 337 if ( e.target.hasClass(CLASS_DISABLED) ) { 338 return; 339 } 340 341 val = e.target.get('value'); 342 this.fire(EVENT_UI, { type: 'perPage', val: parseInt(val, 10) }); 343 }, 344 345 /** 346 Fire EVENT_UI with `type:page` after form is submitted 347 @protected 348 @method _controlSubmit 349 @param {EventFacade} e 350 @since 3.11.0 351 */ 352 _controlSubmit: function (e) { 353 if ( e.target.hasClass(CLASS_DISABLED) ) { 354 return; 355 } 356 357 // the only form we have is the go to page form 358 e.preventDefault(); 359 360 input = e.target.one('input'); 361 362 // Note: Convert input's value into a number. 363 this.fire(EVENT_UI, { type: 'page', val: +input.get('value') }); 364 }, 365 366 /** 367 Initializes classnames to be used with the templates 368 @protected 369 @method _initClassNames 370 @since 3.11.0 371 */ 372 _initClassNames: function () { 373 this.classNames = { 374 control: getClassName(NAME, 'control'), 375 controls: getClassName(NAME, 'controls'), 376 group: getClassName(NAME, 'group'), 377 perPage: getClassName(NAME, 'per-page') 378 }; 379 }, 380 381 /** 382 Initializes strings used for internationalization 383 @protected 384 @method _initStrings 385 @since 3.11.0 386 */ 387 _initStrings: function () { 388 // Not a valueFn because other class extensions may want to add to it 389 this.set('strings', Y.mix((this.get('strings') || {}), 390 Y.Intl.get('datatable-paginator'))); 391 }, 392 393 394 /** 395 Returns an Array with default values for the Rows Per Page select option. 396 We had to use a valueFn to enable language string replacement. 397 398 @protected 399 @method _defPageSizeVal 400 @since 3.13.0 401 */ 402 _defPageSizeVal: function () { 403 this._initStrings(); 404 405 var str = this.get('strings'); 406 407 return [10, 50, 100, { label: str.showAll, value: -1 }] 408 } 409 410 }, { 411 ATTRS: { 412 /** 413 Array of values used to populate the drop down for items per page 414 @attribute pageSizes 415 @type {Array} 416 @default [ 10, 50, 100, { label: 'Show All', value: -1 } ] 417 @since 3.11.0 418 */ 419 pageSizes: { 420 valueFn: '_defPageSizeVal' 421 }, 422 423 /** 424 Model used for this view 425 @attribute model 426 @type {Model} 427 @default null 428 @since 3.11.0 429 */ 430 model: {} 431 } 432 }); 433 434 /** 435 @class DataTable.Paginator 436 @since 3.11.0 437 */ 438 function Controller () {} 439 440 Controller.ATTRS = { 441 /** 442 A model instance or a configuration object for the Model. 443 @attribute paginatorModel 444 @type {Model|Object} 445 @default null 446 @since 3.11.0 447 */ 448 paginatorModel: { 449 setter: '_setPaginatorModel', 450 value: null, 451 writeOnce: 'initOnly' 452 }, 453 454 /** 455 A pointer to a Model object to be instantiated, or a String off of the 456 `Y` namespace. 457 458 This is only used if the `paginatorModel` is a configuration object or 459 is null. 460 @attribute paginatorModelType 461 @type {Model|String} 462 @default 'DataTable.Paginator.Model' 463 @since 3.11.0 464 */ 465 paginatorModelType: { 466 getter: '_getConstructor', 467 value: 'DataTable.Paginator.Model', 468 writeOnce: 'initOnly' 469 }, 470 471 /** 472 A pointer to a `Y.View` object to be instantiated. A new view will be 473 created for each location provided. Each view created will be given the 474 same model instance. 475 @attribute paginatorView 476 @type {View|String} 477 @default 'DataTable.Paginator.View' 478 @since 3.11.0 479 */ 480 paginatorView: { 481 getter: '_getConstructor', 482 value: 'DataTable.Paginator.View', 483 writeOnce: 'initOnly' 484 }, 485 486 // PAGINATOR CONFIGS 487 /** 488 Array of values used to populate the values in the Paginator UI allowing 489 the end user to select the number of items to display per page. 490 @attribute pageSizes 491 @type {Array} 492 @default [10, 50, 100, { label: 'Show All', value: -1 }] 493 @since 3.11.0 494 */ 495 pageSizes: { 496 setter: '_setPageSizesFn', 497 valueFn: '_defPageSizeVal' 498 }, 499 500 paginatorStrings: {}, 501 502 /** 503 Number of rows to display per page. As the UI changes the number of pages 504 to display, this will update to reflect the value selected in the UI 505 @attribute rowsPerPage 506 @type {Number | null} 507 @default null 508 @since 3.11.0 509 */ 510 rowsPerPage: { 511 value: null 512 }, 513 514 /** 515 String of `footer` or `header`, a Y.Node, or an Array or any combination 516 of those values. 517 @attribute paginatorLocation 518 @type {String|Array|Node} 519 @default footer 520 @since 3.11.0 521 */ 522 paginatorLocation: { 523 value: 'footer' 524 } 525 }; 526 527 Y.mix(Controller.prototype, { 528 /** 529 Sets the `paginatorModel` to the first page. 530 @method firstPage 531 @chainable 532 @since 3.11.0 533 */ 534 firstPage: function () { 535 this.get('paginatorModel').set('page', 1); 536 return this; 537 }, 538 539 /** 540 Sets the `paginatorModel` to the last page. 541 @method lastPage 542 @chainable 543 @since 3.11.0 544 */ 545 lastPage: function () { 546 var model = this.get('paginatorModel'); 547 model.set('page', model.get('totalPages')); 548 return this; 549 }, 550 551 /** 552 Sets the `paginatorModel` to the previous page. 553 @method previousPage 554 @chainable 555 @since 3.11.0 556 */ 557 previousPage: function () { 558 this.get('paginatorModel').prevPage(); 559 return this; 560 }, 561 562 /** 563 Sets the `paginatorModel` to the next page. 564 @method nextPage 565 @chainable 566 @since 3.11.0 567 */ 568 nextPage: function () { 569 this.get('paginatorModel').nextPage(); 570 return this; 571 }, 572 573 574 /// Init and protected 575 /** 576 Constructor logic 577 @protected 578 @method initializer 579 @since 3.11.0 580 */ 581 initializer: function () { 582 // allow DT to use paged data 583 this._initPaginatorStrings(); 584 this._augmentData(); 585 586 if (!this._eventHandles.paginatorRender) { 587 this._eventHandles.paginatorRender = Y.Do.after(this._paginatorRender, this, 'render'); 588 } 589 }, 590 591 /** 592 Renders the paginator into locations and attaches events. 593 @protected 594 @method _paginatorRender 595 @since 3.11.0 596 */ 597 _paginatorRender: function () { 598 var model = this.get('paginatorModel'); 599 600 this._paginatorRenderUI(); 601 model.after('change', this._afterPaginatorModelChange, this); 602 this.after('dataChange', this._afterDataChangeWithPaginator, this); 603 this.after('rowsPerPageChange', this._afterRowsPerPageChange, this); 604 this.data.after(['add', 'remove', 'change'], this._afterDataUpdatesWithPaginator, this); 605 606 // ensure our model has the correct totalItems set 607 model.set('itemsPerPage', this.get('rowsPerPage')); 608 model.set('totalItems', this.get('data').size()); 609 }, 610 611 /** 612 After the data changes, we ensure we are on the first page and the data 613 is augmented 614 @protected 615 @method _afterDataChangeWithPaginator 616 @since 3.11.0 617 */ 618 _afterDataChangeWithPaginator: function () { 619 var data = this.get('data'), 620 model = this.get('paginatorModel'); 621 622 model.set('totalItems', data.size()); 623 624 if (model.get('page') !== 1) { 625 this.firstPage(); 626 } else { 627 this._augmentData(); 628 629 data.fire.call(data, 'reset', { 630 src: 'reset', 631 models: data._items.concat() 632 }); 633 } 634 }, 635 636 /** 637 After data has changed due to a model being added, removed, or changed, 638 update paginator model totalItems to reflect the changes. 639 @protected 640 @method _afterDataUpdatesWithPaginator 641 @param {EventFacade} e 642 @since 3.13.0 643 */ 644 _afterDataUpdatesWithPaginator: function () { 645 var model = this.get('paginatorModel'), 646 data = this.get('data'); 647 648 model.set('totalItems', data.size()); 649 }, 650 651 /** 652 After the rowsPerPage changes, update the UI to reflect the new number of 653 rows to be displayed. If the new value is `null`, destroy all instances 654 of the paginators. 655 @protected 656 @method _afterRowsPerPageChange 657 @param {EventFacade} e 658 @since 3.11.0 659 */ 660 _afterRowsPerPageChange: function (e) { 661 var data = this.get('data'), 662 model = this.get('paginatorModel'), 663 view; 664 665 if (e.newVal !== null) { 666 // turning on 667 this._paginatorRenderUI(); 668 669 if (!(data._paged)) { 670 this._augmentData(); 671 } 672 673 data._paged.index = (model.get('page') - 1) * model.get('itemsPerPage'); 674 data._paged.length = model.get('itemsPerPage'); 675 676 } else { // e.newVal === null 677 // destroy! 678 while(this._pgViews.length) { 679 view = this._pgViews.shift(); 680 view.destroy({ remove: true }); 681 view._rendered = null; 682 } 683 684 data._paged.index = 0; 685 data._paged.length = null; 686 } 687 688 this.get('paginatorModel').set('itemsPerPage', parseInt(e.newVal, 10)); 689 }, 690 691 /** 692 Parse each location and render a new view into each area. 693 @protected 694 @method _paginatorRenderUI 695 @since 3.11.0 696 */ 697 _paginatorRenderUI: function () { 698 if (!this.get('rowsPerPage')) { 699 return; 700 } 701 var views = this._pgViews, 702 ViewClass = this.get('paginatorView'), 703 viewConfig = { 704 pageSizes: this.get('pageSizes'), 705 model: this.get('paginatorModel') 706 }, 707 locations = this.get('paginatorLocation'); 708 709 if (!Y.Lang.isArray(locations)) { 710 locations = [locations]; 711 } 712 713 if (!views) { // set up initial rendering of views 714 views = this._pgViews = []; 715 } 716 717 // for each placement area, push to views 718 Y.Array.each(locations, function (location) { 719 var view = new ViewClass(viewConfig), 720 container = view.render().get('container'), 721 row; 722 723 view.after('*:ui', this._uiPgHandler, this); 724 views.push(view); 725 726 if (location._node) { // assume Y.Node 727 location.append(container); 728 // remove this container row if the view is ever destroyed 729 this.after('destroy', function (/* e */) { 730 view.destroy({ remove: true }); 731 }); 732 } else if (location === 'footer') { // DT Footer 733 // Render a table footer if there isn't one 734 if (!this.foot) { 735 this.foot = new Y.DataTable.FooterView({ host: this }); 736 this.foot.render(); 737 this.fire('renderFooter', { view: this.foot }); 738 } 739 740 // create a row for the paginator to sit in 741 row = Y.Node.create(PaginatorTemplates.rowWrapper({ 742 wrapperClass: getClassName(NAME, 'wrapper'), 743 numOfCols: this.get('columns').length 744 })); 745 746 row.one('td').append(container); 747 this.foot.tfootNode.append(row); 748 749 // remove this container row if the view is ever destroyed 750 view.after('destroy', function (/* e */) { 751 row.remove(true); 752 }); 753 } else if (location === 'header') { 754 // 'header' means insert before the table 755 // placement with the caption may need to be addressed 756 if (this.view && this.view.tableNode) { 757 this.view.tableNode.insert(container, 'before'); 758 } else { 759 this.get('contentBox').prepend(container); 760 } 761 } 762 }, this); 763 764 }, 765 766 /** 767 Handles the paginator's UI event into a single location. Updates the 768 `paginatorModel` according to what type is provided. 769 @protected 770 @method _uiPgHandler 771 @param {EventFacade} e 772 @since 3.11.0 773 */ 774 _uiPgHandler: function (e) { 775 // e.type = control type (first|prev|next|last|page|perPage) 776 // e.val = value based on the control type to pass to the model 777 var model = this.get('paginatorModel'); 778 779 switch (e.type) { 780 case 'first': 781 model.set('page', 1); 782 break; 783 case 'last': 784 model.set('page', model.get('totalPages')); 785 break; 786 case 'prev': 787 case 'next': // overflow intentional 788 model[e.type + 'Page'](); 789 break; 790 case 'page': 791 model.set('page', e.val); 792 break; 793 case 'perPage': 794 model.set('itemsPerPage', e.val); 795 model.set('page', 1); 796 break; 797 } 798 }, 799 800 /** 801 Augments the model list with a paged structure, or updates the paged 802 data. Then fires reset on the model list. 803 @protected 804 @method _afterPaginatorModelChange 805 @param {EventFacade} [e] 806 @since 3.11.0 807 */ 808 _afterPaginatorModelChange: function () { 809 var model = this.get('paginatorModel'), 810 data = this.get('data'); 811 812 if (!data._paged) { 813 this._augmentData(); 814 } else { 815 data._paged.index = (model.get('page') - 1) * model.get('itemsPerPage'); 816 data._paged.length = model.get('itemsPerPage'); 817 } 818 819 data.fire.call(data, 'reset', { 820 src: 'reset', 821 models: data._items.concat() 822 }); 823 }, 824 825 /** 826 Augments the model list data structure with paged implementations. 827 828 The model list will contain a method for `getPage` that will return the 829 given number of items listed within the range. 830 831 `each` will also loop over the items in the page 832 @protected 833 @method _augmentData 834 @since 3.11.0 835 */ 836 _augmentData: function () { 837 var model = this.get('paginatorModel'); 838 839 if (this.get('rowsPerPage') === null) { 840 return; 841 } 842 843 Y.mix(this.get('data'), { 844 845 _paged: { 846 index: (model.get('page') - 1) * model.get('itemsPerPage'), 847 length: model.get('itemsPerPage') 848 }, 849 850 getPage: function () { 851 var _pg = this._paged, 852 min = _pg.index; 853 854 // IE LTE 8 doesn't allow "undefined" as a second param - gh890 855 return (_pg.length >= 0) ? 856 this._items.slice(min, min + _pg.length) : 857 this._items.slice(min); 858 }, 859 860 size: function (paged) { 861 return (paged && this._paged.length >=0 ) ? 862 this._paged.length : 863 this._items.length; 864 }, 865 866 each: function () { 867 var args = Array.prototype.slice.call(arguments); 868 args.unshift(this.getPage()); 869 870 Y.Array.each.apply(null, args); 871 872 return this; 873 } 874 }, true); 875 }, 876 877 /** 878 Ensures `pageSizes` value is an array of objects to be used in the 879 paginator view. 880 @protected 881 @method _setPageSizesFn 882 @param {Array} val 883 @return Array 884 @since 3.11.0 885 */ 886 _setPageSizesFn: function (val) { 887 var i, 888 len = val.length, 889 label, 890 value; 891 892 if (!Y.Lang.isArray(val)) { 893 val = [val]; 894 len = val.length; 895 } 896 897 for ( i = 0; i < len; i++ ) { 898 if (typeof val[i] !== 'object') { 899 label = val[i]; 900 value = val[i]; 901 902 // We want to check to see if we have a number or a string 903 // of a number. If we do not, we want the value to be -1 to 904 // indicate "all rows" 905 /*jshint eqeqeq:false */ 906 if (parseInt(value, 10) != value) { 907 value = -1; 908 } 909 /*jshint eqeqeq:true */ 910 val[i] = { label: label, value: value }; 911 } 912 } 913 914 return val; 915 }, 916 917 /** 918 Ensures the object provided is an instance of a `Y.Model`. If it is not, 919 it assumes it is the configuration of a model, and gets the new model 920 type from `paginatorModelType`. 921 @protected 922 @method _setPaginatorModel 923 @param {Model|Object} model 924 @return Y.Model instance 925 @since 3.11.0 926 */ 927 _setPaginatorModel: function (model) { 928 if (!(model && model._isYUIModel)) { 929 var ModelConstructor = this.get('paginatorModelType'); 930 model = new ModelConstructor(model); 931 } 932 933 return model; 934 }, 935 936 /** 937 Returns a pointer to an object to be instantiated if the provided type is 938 a string 939 @protected 940 @method _getConstructor 941 @param {Object | String} type Type of Object to contruct. If `type` is a 942 String, we assume it is a namespace off the Y object 943 @return 944 @since 3.11.0 945 */ 946 _getConstructor: function (type) { 947 return typeof type === 'string' ? 948 Y.Object.getValue(Y, type.split('.')) : 949 type; 950 }, 951 952 /** 953 Initializes paginatorStrings used for internationalization 954 @protected 955 @method _initPaginatorStrings 956 @since 3.13.0 957 */ 958 _initPaginatorStrings: function () { 959 // Not a valueFn because other class extensions may want to add to it 960 this.set('paginatorStrings', Y.mix((this.get('paginatorStrings') || {}), 961 Y.Intl.get('datatable-paginator'))); 962 }, 963 964 /** 965 Returns an Array with default values for the Rows Per Page select option. 966 We had to use a valueFn to enable language string replacement. 967 968 @protected 969 @method _defPageSizeVal 970 @since 3.13.0 971 */ 972 _defPageSizeVal: function () { 973 this._initPaginatorStrings(); 974 975 var str = this.get('paginatorStrings'); 976 977 return [10, 50, 100, { label: str.showAll, value: -1 }] 978 } 979 }, true); 980 981 982 Y.DataTable.Paginator = Controller; 983 Y.DataTable.Paginator.Model = Model; 984 Y.DataTable.Paginator.View = View; 985 986 Y.Base.mix(Y.DataTable, [Y.DataTable.Paginator]); 987 988 989 }, '3.17.2', { 990 "requires": [ 991 "model", 992 "view", 993 "paginator-core", 994 "datatable-foot", 995 "datatable-paginator-templates" 996 ], 997 "lang": [ 998 "en", 999 "fr" 1000 ], 1001 "skinnable": true 1002 });
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |