116 lines
4.7 KiB
HTML
116 lines
4.7 KiB
HTML
function () {
|
||
var boDefName = "<#boDefName>";
|
||
var boItemDefName = "<#boItemDefName>";
|
||
var uiId = "<#uiId>";
|
||
var uiSetting =<#uiSetting>;
|
||
var componentExtendCode = "<#componentExtendCode>";
|
||
var tooltip = "<#tooltip>";
|
||
if(window.initKnwlObj === undefined){//加载页面后初始化一次,每次做修改删除时相应的改变值
|
||
window.initKnwlObj = <#initKnwlJO>;
|
||
}
|
||
return function () {
|
||
|
||
|
||
$("#awsui_tooltip").remove();
|
||
var $cell = ui.$cell, data = ui.data, rowIndx = ui.rowIndxPage, colIndx = ui.colIndx;
|
||
var rowData = ui.rowData;
|
||
// var dataCell = $.trim(data[rowIndx][colIndx]);
|
||
if (tooltip == undefined) {
|
||
tooltip = "";
|
||
}
|
||
$cell.append('<select id="'+boDefName+boItemDefName+'Select2" class="js-data-example-ajax" style="width:100%;" multiple="multiple"></select>');
|
||
var $select = $cell.children("select");
|
||
$select.select2({
|
||
placeholder: "请输入知识名称检索...",
|
||
ajax: {
|
||
url: "./jd",
|
||
dataType: 'json',
|
||
delay: 250,
|
||
data: function (params) {
|
||
return {
|
||
sid: $('#sid').val(),
|
||
cmd: 'com.actionsoft.apps.kms_knwl_attr_search_dosearch',
|
||
curPage: params.page || 1,
|
||
rowsPerPage: 10,
|
||
searchDimensionIds: JSON.stringify([]),
|
||
schemaMetaData: encodeURIComponent(JSON.stringify({'01': [], '2': []})),
|
||
cardName: params.term,
|
||
publishTime: JSON.stringify({"startPublishTime": "", "endPublishTime": ""}),
|
||
publishUser: '',
|
||
tags: encodeURIComponent(JSON.stringify([])),
|
||
sortIndx: 'publishTime',
|
||
sortDir: 'down'
|
||
};
|
||
},
|
||
processResults: function (data, params) {
|
||
params.page = data.data.curPage || 1;
|
||
return {
|
||
results: data.data.data,
|
||
pagination: {
|
||
more: (params.page * 10) < data.data.totalRecords
|
||
}
|
||
};
|
||
},
|
||
cache: true
|
||
},
|
||
escapeMarkup: function (markup) {
|
||
return markup;
|
||
},
|
||
minimumInputLength: 0,
|
||
templateResult: function (repo) {
|
||
var markup = repo.cardName + " (" + repo.publishUsername + " 发布于 " + repo.publishTime + ")";
|
||
return markup;
|
||
},
|
||
templateSelection: function (repo) {
|
||
//修改内存中的initKnwlObj
|
||
var arr = initKnwlObj[rowData.ID];
|
||
if(!arr){
|
||
arr = [];
|
||
}
|
||
var indx = -1;
|
||
var obj;
|
||
var arrNew = $.each(arr,function(i,n){
|
||
indx++;
|
||
if(n.id == repo.id){
|
||
obj = n;
|
||
return false;
|
||
}
|
||
});
|
||
if(!obj){//不存在则添加
|
||
arr[arr.length] = {id:repo.id,cardName:(repo.cardName || repo.text)};
|
||
initKnwlObj[rowData.ID] = arr;
|
||
}
|
||
return repo.cardName || repo.text;
|
||
},
|
||
allowClear: true
|
||
});
|
||
|
||
$select.on('select2:unselect', function(e) {
|
||
try{
|
||
//修改内存中的initKnwlObj
|
||
var arr = initKnwlObj[rowData.ID];
|
||
var arrCurr = $select.val();
|
||
var indx = -1;
|
||
$.each(arr,function(i,n){
|
||
indx++;
|
||
if(arrCurr.indexOf(n.id) === -1){
|
||
return false;
|
||
}
|
||
});
|
||
arr.splice(indx,1);
|
||
<!--//如果是来自x号的unselect操作,组织冒泡到grid,否则会触发grid的退出编辑动作-->
|
||
if(e.params.originalEvent.currentTarget.className === 'select2-selection__choice__remove'){
|
||
}
|
||
}catch(e){}
|
||
});
|
||
var initKnwlArr = initKnwlObj[rowData.ID];
|
||
if(initKnwlArr){
|
||
for (var i = 0; i < initKnwlArr.length; i++) {
|
||
var option = initKnwlArr[i];
|
||
var $option = $('<option selected>' + option.cardName + '</option>').val(option.id);
|
||
$select.append($option);
|
||
}
|
||
$select.trigger('change');
|
||
}
|
||
}(ui, boDefName, boItemDefName, uiId, uiSetting, componentExtendCode, tooltip);
|
||
}(ui); |