YUI.add('mappingtable', function(Y) { var Lang = Y.Lang, Node = Y.Node, SOURCE_COLUMN = 0, TARGET_COLUMN = 1, Widget = Y.Widget; function MappingTable(config) { MappingTable.superclass.constructor.apply(this, arguments); } MappingTable.NAME = "mappingtable"; MappingTable.ATTRS = { srcNode: { value: null }, strategy: { value: null }, focus: { value: null }, datasource: { value: null }, showRelation: { value: false }, vocs: { value: { source: null, target: null }}, rows: { value:100, validator:function(val) { return Lang.isNumber(val); }}, loading: { value:false, validator:function(val) { return Lang.isBoolean(val); }} }; Y.extend(MappingTable, Y.Base, { initializer: function(config) { var instance = this, content = this.get("srcNode"); this._tableNode = content.appendChild(Node.create( '
' )); this._loadingNode = content.appendChild(Node.create( '' )); var s_column = { key:"source", formatter:this.formatResource, allowHTML: true, sortable:true }; var t_column = { key:"target", formatter:this.formatResource, allowHTML: true, sortable:true }; var r_column = { key:"relation", label: 'manually assigned relation', formatter:this.formatRelation, allowHTML: true, sortable:true }; var columns = []; SOURCE_COLUMN = 0 if (this.get('showRelation')) { columns = [s_column, r_column, t_column]; TARGET_COLUMN = 2; } else { columns = [s_column, t_column]; } this.table = new Y.DataTable({columns:columns}).render(this._tableNode); this.paginator = new Y.Paginator({ rowsPerPage:this.get("rows"), template: '{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}', firstPageLinkLabel:'|<', previousPageLinkLabel: '<', nextPageLinkLabel: '>', lastPageLinkLabel: '>|' }) .render(content.appendChild(Node.create( '' ))); this.paginator.on("changeRequest", function(state) { this.setPage(state.page, true); instance.loadData({offset:state.recordOffset}, true); }); this.on('loadingChange', this._onLoadingChange, this); // get new data if mapping is changed this.after('focusChange', function() {this.loadData()}, this); this.table.delegate('click', this._onRowSelect, '.yui3-datatable-data tr', this); this.loadData(); }, loadData : function(conf, recordsOnly) { var oSelf = this, s = this.get("focus"), datasource = this.get("datasource"), strategy = this.get("strategy"), table = this.table, paginator = this.paginator; var callback = { success: function(o) { var records = o.response.results, total = o.response.meta.totalNumberOfResults; if(!recordsOnly) { paginator.setPage(1, true); paginator.setTotalRecords(total, true); } var vocs = o.response.meta.stats.vocs; if (vocs) { var sL = vocs.source.label + ' (source terms from: ' + s.abbrev + '.' + s.label + ')'; var tL = vocs.target.label + ' (target terms from: ' + s.abbrev + '.' + s.label + ')'; table.head.columns[0][SOURCE_COLUMN].label = sL; table.head.columns[0][TARGET_COLUMN].label = tL; table.set("data", records); table.syncUI(); oSelf.set("vocs", vocs); } oSelf.set("loading", false); } }; if(s) { // selected mapping s conf = conf ? conf : {}; conf.url = s.uri; conf.strategy=strategy; conf.limit=this.get('rows'); this.set("loading", true); datasource.sendRequest({ request:'?'+Y.QueryString.stringify(conf), callback:callback }) } else { paginator.setTotalRecords(0, true); table.set("data", []); } }, formatResource : function(o) { var label = o.value ? o.value.label : ""; return "