sap ui define sap Table function Table return Table extend sap cc cont

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
sap.ui.define([
"sap/m/Table"
], function(Table) {
return Table.extend("sap.cc.control.CopyPasteTable", {
onInit: function() {
console.log("Init: sap.cc.control.CopyPasteTable");
},
onAfterRendering: function () {
console.log("onAfterRendering: sap.cc.control.CopyPasteTable");
var that = this;
sap.m.Table.prototype.onAfterRendering.apply(this, arguments);
this.attachBrowserEvent('paste', function(e){
console.log("entering method: attachBrowserEvent");
e.preventDefault();
var text = (e.originalEvent || e).clipboardData.getData('text/plain');
that.insertRows(text,this,undefined);
});
var items = this.getAggregation('items');
if(items == undefined){
console.log("items undefined!");
return;
}
items.forEach(function(row) {
console.log("entering method: getAggregation");
row.getCells().forEach(function(cell) {
console.log("entering method: forEach");
cell.attachBrowserEvent('paste',function(e){
console.log("entering method: attachBrowserEvent");
var text = "";
if (window.clipboardData) { // Internet Explorer
text = window.clipboardData.getData('Text');
} else {
text = (e.originalEvent || e).clipboardData.getData('text/plain');
}
var flag = text.search(/\t/);
if(flag === -1){
console.log("no tab symbol, that means this simple string");
e.stopPropagation();
} else {
console.log("has tab symbol, that means string from excel");
e.stopPropagation();
e.preventDefault();
}
var domCell = jQuery.sap.domById(e.currentTarget.id)
var insertCell = jQuery('#'+domCell.id).control()[0];
var itemsPath = that.getBindingPath('items');
var pathRow = insertCell.getBindingContext().sPath;
var startRowIndex = pathRow.split(itemsPath+"/")[1];
var startProperty = insertCell.getBindingPath('value');
that.insertRows(text, that, undefined, startRowIndex, startProperty);
});
});
});
},
insertRows:function(value,table,model,startRowIndex,startProperty){
var that = this;
var rows = value.split(/\n/);
var cells = table.getBindingInfo('items').template.getCells();
var templateItem = [];
var itemsPath = table.getBindingPath('items');
var itemsArray = table.getModel(model).getProperty(itemsPath);
var startPropertyIndex = 0;
var model = table.getModel(model);
if(startRowIndex === undefined){
startRowIndex = 0;
}
for (var int = 0; int < cells.length; int++) {
var cell_element = cells[int];
var path = cell_element.getBindingPath('value');
if(path == undefined){
path = cell_element.getBindingPath('selectedKey');
}
if(path == undefined){
path = cell_element.getBindingPath('text');
}
templateItem.push(path);
if(path === startProperty){
startPropertyIndex = int;
}
}
for (var int = 0; int < rows.length-1; int++) {
var rows_element = rows[int];
var cells = rows_element.split(/\t/);
var originalObject = model.getProperty(itemsPath+"/"+startRowIndex++);
if(originalObject === undefined){
originalObject = {};
for(var k =0; k < templateItem.length; k++){
originalObject[templateItem[k]] =undefined;
}
itemsArray.push(originalObject);
}
var lesserLength = Math.min(templateItem.length,(cells.length + startPropertyIndex));
for(int2 = startPropertyIndex,intValue=0; int2 < lesserLength; int2++,intValue++){
var name = templateItem[int2];
originalObject[name] = cells[intValue];
}
}
// row numbers
var list = this.getModel().getProperty('/items');
for (var int = 0; int < list.length; int++) {
var elem = list[int];
var a = int + 1;
elem.id = "" + a;
}
model.refresh();
},
renderer: sap.m.Table.prototype.getRenderer()
});
});