portal-table.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. if($ == undefined){
  2. $ = jQuery;
  3. }
  4. function selecttable(){
  5. $('#pdailog').dialog({
  6. title: '选择数据集',
  7. width: 400,
  8. height: 350,
  9. closed: false,
  10. cache: false,
  11. modal: true,
  12. toolbar:null,
  13. content:'<ul id="targettables"></ul>',
  14. onLoad:function(){
  15. },
  16. buttons:[{
  17. text:'确定',
  18. iconCls:"icon-ok",
  19. handler:function(){
  20. var node = $("#targettables").tree("getSelected");
  21. if(node == null){
  22. msginfo("请选择表!");
  23. return;
  24. }
  25. pageInfo.table = {dsetId:node.attributes.dsetId, dsid:node.attributes.dsid,dsetName:node.attributes.dsetName,priTable:node.attributes.priTable};
  26. $("#comp_tab").tabs("select", 2);
  27. initTableTree();
  28. curTmpInfo.isupdate = true;
  29. $('#pdailog').dialog('close');
  30. }
  31. },{
  32. text:'取消',
  33. iconCls:"icon-cancel",
  34. handler:function(){
  35. $('#pdailog').dialog('close');
  36. }
  37. }]
  38. });
  39. $.getJSON("../model/listDataset.action", {t:Math.random()}, function(dt){
  40. for(i=0; i<dt.length; i++){
  41. dt[i].id = dt[i].dsetId;
  42. dt[i].text = dt[i].name + "(" + dt[i].priTable + ")";
  43. dt[i].iconCls = 'icon-table';
  44. dt[i].attributes = {dsetId: dt[i].dsetId,dsetName:dt[i].name,priTable:dt[i].priTable, dsid:dt[i].dsid};
  45. }
  46. $("#targettables").tree({
  47. data:dt
  48. });
  49. });
  50. }
  51. function initTableTree(){
  52. if(!pageInfo.table){
  53. $("#tabletree").tree({
  54. lines:true,
  55. data:[{id:'nodata', text:'您还未选择数据表!', iconCls:'icon-no'}]
  56. });
  57. }else{
  58. var t = pageInfo.table;
  59. var dt = {id:t.dsetId, text:t.dsetName+"("+t.priTable+")",iconCls:'icon-table', children:[]};
  60. $.getJSON("../model/getDatasetCfg.action", {dsetId:t.dsetId,t:Math.random()}, function(resp){
  61. ret = resp.cols;
  62. for(i=0; i<ret.length; i++){
  63. dt.children.push({id:ret[i].name, text:ret[i].name, iconCls:'icon-dscol',attributes:{id:ret[i].name,name:ret[i].name,dsetId:t.dsetId,dsid:t.dsid, tname:ret[i].tname,type:ret[i].type, expression: ret[i].expression}});
  64. }
  65. //添加动态字段
  66. dyna = resp.dynamic;
  67. for(i=0; dyna&&dyna!=null&&i<dyna.length; i++){
  68. var r = dyna[i];
  69. dt.children.push({id:r.name, text:r.name, iconCls:'icon-dscol',attributes:{id:r.name,name:r.name,dsetId:t.dsetId,dsid:t.dsid, tname:r.tname,type:r.type, expression: r.expression}});
  70. }
  71. $("#tabletree").tree({
  72. lines:true,
  73. dnd:true,
  74. data:[dt],
  75. onBeforeDrag:function(target){
  76. if(!target.attributes || target.attributes.tp == 'root'){
  77. return false;
  78. }
  79. return true;
  80. },
  81. onDragEnter:function(target, source){
  82. return false;
  83. },
  84. onContextMenu:function(e, node){
  85. e.preventDefault();
  86. }
  87. });
  88. });
  89. }
  90. }
  91. function editGridData(compId){
  92. if($("#dataProperty").size() == 0){
  93. $('#Jlayout').layout('add', {region:"south", id:"dataProperty", split:false, collapsible:false,height : 120, title:'编辑表格数据', tools:[{
  94. iconCls:'icon-cancel',
  95. handler:function(){
  96. $('#Jlayout').layout("remove", "south");
  97. }
  98. }]});
  99. }else{
  100. $('#Jlayout').layout('panel', "south").panel("setTitle", "编辑表格数据");
  101. }
  102. //切换到数据表
  103. $("#comp_tab").tabs("select", 2);
  104. var comp = findCompById(compId);
  105. var str = "";
  106. for(var i=0; comp.cols&&i<comp.cols.length; i++){
  107. var o = comp.cols[i];
  108. str = str + "<span id=\"d_"+o.id+"\" class=\"dimcol\"><span class=\"text\">"+o.name+"</span><div class=\"ibox-tools\"><button class=\"btn btn-outline btn-success btn-xs\" onclick=\"setGridCol(this, '"+o.id+"', '"+o.name+"','"+compId+"')\"><i class=\"fa fa-wrench\"></i></button></div></span>";
  109. }
  110. if(str == ""){
  111. str = "<div class=\"tipinfo\">拖拽数据表字段到此处作为表格的列字段</div>";
  112. }else{
  113. str = "<span id=\"tabRows\"><b>表格字段:</b>" + str + "</span>";
  114. }
  115. var ctx = "<div style=\"margin:10px;\"><div class=\"tableDatasty\" id=\"gridData\">"+str +"</div></div>";
  116. $("#dataProperty").html(ctx);
  117. //注册接收度量及维度拖放事件
  118. $("#gridData").droppable({
  119. accept:"#tabletree .tree-node",
  120. onDragEnter:function(e,source){
  121. //对维度拖拽设置图标
  122. $(source).draggable('proxy').find("span").removeClass("tree-dnd-no");
  123. $(source).draggable('proxy').find("span").addClass("tree-dnd-yes");
  124. $("#gridData").css("border", "1px solid #ff0000");
  125. e.cancelBubble=true;
  126. e.stopPropagation(); //阻止事件冒泡
  127. },
  128. onDragLeave:function(e,source){
  129. $(source).draggable('proxy').find("span").addClass("tree-dnd-no");
  130. $(source).draggable('proxy').find("span").removeClass("tree-dnd-yes");
  131. $("#gridData").css("border", "1px dotted #666");
  132. e.cancelBubble=true;
  133. e.stopPropagation(); //阻止事件冒泡
  134. },
  135. onDrop:function(e,source){
  136. var grid = findCompById(compId);
  137. e.cancelBubble=true;
  138. e.stopPropagation(); //阻止事件冒泡
  139. //清除边框颜色
  140. $("#gridData").css("border", "1px dotted #666");
  141. //获取TREE
  142. var node = $("#tabletree").tree("getNode", source);
  143. if(grid.dsetId && grid.dsetId != node.attributes.dsetId){
  144. msginfo("你拖入的字段"+node.text+"与表格已有的内容不在同一个表中,拖放失败!");
  145. return;
  146. }else{
  147. grid.dsetId = node.attributes.dsetId;
  148. grid.dsid = node.attributes.dsid;
  149. }
  150. if(!grid.cols){
  151. grid.cols = [];
  152. }
  153. //判断是否存在
  154. var exist = function(gid){
  155. var r = false;
  156. for(j=0; j<grid.cols.length; j++){
  157. if(grid.cols[j].id == gid){
  158. r = true;
  159. break;
  160. }
  161. }
  162. return r;
  163. };
  164. if(exist(node.id)){
  165. msginfo("您拖拽的字段 " + node.text+" 已经存在。");
  166. return;
  167. }
  168. grid.cols.push({id:node.id,name:node.attributes.name,tname:node.attributes.tname,type:node.attributes.type,expression:node.attributes.expression});
  169. var str = "<span id=\"d_"+node.id+"\" class=\"dimcol\"><span class=\"text\">"+node.text+"</span><div class=\"ibox-tools\"><button class=\"btn btn-outline btn-success btn-xs\" onclick=\"setGridCol(this, '"+node.id+"', '"+node.text+"','"+compId+"')\"><i class=\"fa fa-wrench\"></i></button></div></span>";
  170. var obj = $("#gridData");
  171. if(obj.find("#tabRows").size() == 0){
  172. obj.html("<span id=\"tabRows\"><b>表格字段:</b>"+str+"</span>");
  173. }else{
  174. $("#gridData #tabRows").find("span.dimcol").last().after(str);
  175. }
  176. curTmpInfo.isupdate = true;
  177. gridView(grid);
  178. }
  179. });
  180. }
  181. function gridView(grid){
  182. if(!grid){
  183. return;
  184. }
  185. if(!grid.cols || grid.cols.length==0){
  186. return;
  187. }
  188. var json = eval("("+JSON.stringify(grid)+")");
  189. json.portalParams = pageInfo.params;
  190. __showLoading();
  191. $.ajax({
  192. type: "POST",
  193. url: "GridView.action",
  194. contentType : "application/json",
  195. dataType:"html",
  196. data: JSON.stringify(json),
  197. success: function(resp){
  198. __hideLoading();
  199. $("#c_" + grid.id + " div.cctx div.ccctx").html(resp);
  200. },
  201. error:function(resp){
  202. __hideLoading();
  203. $.messager.alert('出错了','系统出错,请查看后台日志。','error');
  204. }
  205. });
  206. }
  207. function setGridCol(ts, id, name, compId){
  208. var offset = $(ts).offset();
  209. //放入临时对象中,方便下次获
  210. curTmpInfo.ckid = id;
  211. curTmpInfo.compId = compId;
  212. curTmpInfo.dimname = name;
  213. var comp = findCompById(compId);
  214. var col = findColById(id, comp);
  215. if(col.sort == 'asc'){
  216. $("#gridoptmenu").menu("setIcon", {target:$("#gridoptmenu").menu("getItem", $("#col_ord1")).target, iconCls:"icon-ok"});
  217. $("#gridoptmenu").menu("setIcon", {target:$("#gridoptmenu").menu("getItem", $("#col_ord2")).target, iconCls:"icon-blank"});
  218. $("#gridoptmenu").menu("setIcon", {target:$("#gridoptmenu").menu("getItem", $("#col_ord3")).target, iconCls:"icon-blank"});
  219. }else if(col.sort == 'desc'){
  220. $("#gridoptmenu").menu("setIcon", {target:$("#gridoptmenu").menu("getItem", $("#col_ord1")).target, iconCls:"icon-blank"});
  221. $("#gridoptmenu").menu("setIcon", {target:$("#gridoptmenu").menu("getItem", $("#col_ord2")).target, iconCls:"icon-ok"});
  222. $("#gridoptmenu").menu("setIcon", {target:$("#gridoptmenu").menu("getItem", $("#col_ord3")).target, iconCls:"icon-blank"});
  223. }else{
  224. $("#gridoptmenu").menu("setIcon", {target:$("#gridoptmenu").menu("getItem", $("#col_ord1")).target, iconCls:"icon-blank"});
  225. $("#gridoptmenu").menu("setIcon", {target:$("#gridoptmenu").menu("getItem", $("#col_ord2")).target, iconCls:"icon-blank"});
  226. $("#gridoptmenu").menu("setIcon", {target:$("#gridoptmenu").menu("getItem", $("#col_ord3")).target, iconCls:"icon-ok"});
  227. }
  228. $("#gridoptmenu").menu("show", {left:offset.left, top:offset.top - 96});
  229. }
  230. function gridColsort(tp){
  231. var id = curTmpInfo.ckid;
  232. var compId = curTmpInfo.compId;
  233. var comp = findCompById(compId);
  234. var col = findColById(id, comp);
  235. //清楚其他字段的排序
  236. for(i=0; i<comp.cols.length; i++){
  237. delete comp.cols[i].sort;
  238. }
  239. if(tp != ""){
  240. col.sort = tp;
  241. }
  242. curTmpInfo.isupdate = true;
  243. gridView(comp);
  244. }
  245. function setGridColProp(){
  246. var id = curTmpInfo.ckid;
  247. var compId = curTmpInfo.compId;
  248. var comp = findCompById(compId);
  249. var col = findColById(id, comp);
  250. var fmtstr = "";
  251. if(col.type == "Double" || col.type == "Int"){
  252. fmtstr = "<span class='inputtext'>格 式 化:</span><select id=\"fmt\" name=\"fmt\" class=\"inputform2\"><option value=\"\"></option><option value=\"###,##0\" "+(col.fmt=="###,##0"?"selected":"")+">整数</option><option value=\"###,##0.0\" "+(col.fmt=="###,##0.0"?"selected":"")+">小数(保留1位)</option><option value=\"###,##0.00\" "+(col.fmt=="###,##0.00"?"selected":"")+">小数(保留2位)</option><option value=\"0.00%\" "+(col.fmt=="0.00%"?"selected":"")+">百分比</option></select><br/>";
  253. }
  254. if(col.type == "Date" || col.type == "Datetime"){
  255. fmtstr = "<span class='inputtext'>格 式 化:</span><input type='text' id='fmt' name='fmt' class='inputform2' value=\""+(col.fmt?col.fmt:"")+"\"><br/>";
  256. }
  257. var ctx = "<div class=\"textpanel\"><span class='inputtext'>显示名称:</span><input type=\"text\" id=\"dispName\" name=\"dispName\" class=\"inputform2\" value=\""+(col.dispName?col.dispName:"")+"\"><br><span class='inputtext'>所 属 表: </span>"+col.tname+"<br><span class='inputtext'>对应字段:</span> "+col.name+"<br>"+fmtstr+"<span class='inputtext'>位置:</span><select id=\"palign\" name=\"palign\" class=\"inputform2\"><option value=\"\"></option><option value=\"left\" "+(col.align=="left"?"selected":"")+">居左</option><option value=\"center\" "+(col.align=="center"?"selected":"")+">居中</option><option value=\"right\" "+(col.align=="right"?"selected":"")+">居右</option></select></div>";
  258. $('#pdailog').dialog({
  259. title: '表格字段属性',
  260. width: 350,
  261. height: 270,
  262. closed: false,
  263. cache: false,
  264. modal: true,
  265. toolbar:null,
  266. content: ctx,
  267. buttons:[{
  268. text:'确定',
  269. iconCls:"icon-ok",
  270. handler:function(){
  271. var dispName = $("#pdailog #dispName").val();
  272. var fmt = $("#pdailog #fmt").val();
  273. var align = $("#pdailog #palign").val();
  274. col.dispName = dispName;
  275. col.fmt = fmt;
  276. col.align = align;
  277. $('#pdailog').dialog('close');
  278. curTmpInfo.isupdate = true;
  279. gridView(comp);
  280. }
  281. },{
  282. text:'取消',
  283. iconCls:"icon-cancel",
  284. handler:function(){
  285. $('#pdailog').dialog('close');
  286. }
  287. }]
  288. });
  289. }
  290. function tableColmove(tp){
  291. var id = curTmpInfo.ckid;
  292. var compId = curTmpInfo.compId;
  293. var comp = findCompById(compId);
  294. var dims = comp.cols;
  295. if(dims.length <= 1){
  296. msginfo('无效移动。');
  297. return;
  298. }
  299. for(var i=0; i<dims.length; i++){
  300. if(dims[i].id == id){
  301. if(tp == 'left'){
  302. if(i <= 0){
  303. msginfo('无效移动。');
  304. return;
  305. }else{
  306. var tp = dims[i - 1];
  307. dims[i - 1] = dims[i];
  308. dims[i] = tp;
  309. //交换维度
  310. $("#gridData #d_"+id).prev().before($("#gridData #d_"+id));
  311. curTmpInfo.isupdate = true;
  312. gridView(comp);
  313. return;
  314. }
  315. }else
  316. if(tp == 'right'){
  317. if( i >= dims.length - 1){
  318. msginfo('无效移动。');
  319. return;
  320. }else{
  321. var tp = dims[i + 1];
  322. dims[i + 1] = dims[i];
  323. dims[i] = tp;
  324. //交换维度
  325. $("#gridData #d_"+id).next().after($("#gridData #d_"+id));
  326. curTmpInfo.isupdate = true;
  327. gridView(comp);
  328. return;
  329. }
  330. }
  331. break;
  332. }
  333. }
  334. }
  335. function delGridCol(){
  336. var id = curTmpInfo.ckid;
  337. var compId = curTmpInfo.compId;
  338. var comp = findCompById(compId);
  339. if(comp.cols.length == 1){
  340. msginfo("表格至少需要含有一个字段。");
  341. return;
  342. }
  343. //从json移除
  344. var idx = -1;
  345. for(i=0; i<comp.cols.length; i++){
  346. var p = comp.cols[i];
  347. if(p.id == id){
  348. idx = i;
  349. break;
  350. }
  351. }
  352. comp.cols.splice(idx, 1);
  353. $("#gridData #d_" + id).remove();
  354. curTmpInfo.isupdate = true;
  355. gridView(comp);
  356. }
  357. function setGridProperty(comp){
  358. if($("#compSet").size() == 0){
  359. $('#Jlayout').layout('add', {region:"east", split:false, width:240, title:"表格属性配置", collapsible:false, id:"compSet", tools:[{
  360. iconCls:'icon-cancel',
  361. handler:function(){
  362. $('#Jlayout').layout("remove", "east");
  363. }
  364. }]});
  365. }else{
  366. $('#Jlayout').layout('panel', "east").panel("setTitle", "表格属性配置");
  367. }
  368. $('#compSet').propertygrid({
  369. showGroup:true,
  370. border:false,
  371. showHeader:false,
  372. scrollbarSize: 0,
  373. fitColumns:false,
  374. onAfterEdit: function(rowIndex,rowData,changes){
  375. var val = rowData.value;
  376. var col = rowData.col;
  377. curTmpInfo.isupdate = true;
  378. if(col == "name"){
  379. comp.name = val;
  380. $("#c_"+comp.id + " div.ctit h5").text(val);
  381. }else{
  382. if(comp[col] == val){
  383. return; //值未变
  384. }
  385. comp[col] = val;
  386. }
  387. if( col == "lockhead" || col == "isnotfy" || col == "pageSize"){
  388. gridView(comp);
  389. }
  390. },
  391. data:[
  392. {name:'表格标题',col:'name', value:(comp.name?comp.name:""), group:'表格属性', editor:'text'},
  393. {name:'是否显示标题',col:'showtitle', value:(comp.showtitle?comp.showtitle:"true"), group:'表格属性', editor:{
  394. type:"checkbox",
  395. options:{"on":true, "off":false}
  396. }},
  397. {name:'禁用分页',col:'isnotfy', value:(comp.isnotfy?comp.isnotfy:""), group:'表格属性', editor:{
  398. type:"checkbox",
  399. options: {"on":true, "off":false}
  400. }},
  401. {name:'每页显示条数',col:'pageSize', value:(comp.pageSize?comp.pageSize:"10"), group:'表格属性', editor:{type:'numberspinner',options:{min:1,max:100,increment:5}}}
  402. ]
  403. });
  404. }
  405. function setBoxProperty(comp){
  406. if($("#compSet").size() == 0){
  407. $('#Jlayout').layout('add', {region:"east", split:false, width:240, title:"数据块属性配置", collapsible:false, id:"compSet", tools:[{
  408. iconCls:'icon-cancel',
  409. handler:function(){
  410. $('#Jlayout').layout("remove", "east");
  411. }
  412. }]});
  413. }else{
  414. $('#Jlayout').layout('panel', "east").panel("setTitle", "数据块属性配置");
  415. }
  416. $('#compSet').propertygrid({
  417. showGroup:true,
  418. border:false,
  419. showHeader:false,
  420. scrollbarSize: 0,
  421. fitColumns:false,
  422. onAfterEdit: function(rowIndex,rowData,changes){
  423. var val = rowData.value;
  424. var col = rowData.col;
  425. curTmpInfo.isupdate = true;
  426. if(col == "name"){
  427. comp.name = val;
  428. $("#c_"+comp.id + " div.ctit h5").text(val);
  429. }else if(col == "bgcolor"){
  430. comp[col] = val;
  431. if(val == ""){ //
  432. $("#c_"+comp.id + " div.ibox-content").css("background-color", "inherit");
  433. }else{
  434. $("#c_"+comp.id + " div.ibox-content").css("background-color", val);
  435. }
  436. }else if(col == "showtitle" ){
  437. comp[col] = val;
  438. }else{
  439. if(comp.kpiJson[col] == val){ //值未改变
  440. return;
  441. }
  442. comp.kpiJson[col] = val;
  443. boxView(comp);
  444. }
  445. },
  446. data:[
  447. {name:'标题',col:'name', value:(comp.name?comp.name:""), group:'数据块属性', editor:'text'},
  448. {name:'单位',col:'unit', value:(comp.kpiJson&&comp.kpiJson!=null?comp.kpiJson.unit:""), group:'数据块属性', editor:'text'},
  449. {name:'格式化',col:'fmt', value:(comp.kpiJson&&comp.kpiJson!=null?comp.kpiJson.fmt:""), group:'数据块属性', editor:{
  450. type:'combobox',
  451. options:{data:fmtJson}
  452. }},
  453. {name:'度量比例',col:'rate', value:(comp.kpiJson&&comp.kpiJson!=null?comp.kpiJson.rate:""), group:'数据块属性', editor:{
  454. type:'combobox',
  455. options:{data:kpirate}
  456. }},
  457. {name:'字体大小',col:'tfontsize', value:(comp.kpiJson&&comp.kpiJson.tfontsize?comp.kpiJson.tfontsize:"32"), group:'数据块属性', editor:{type:'numberspinner',options:{min:9,max:100,increment:3}}},
  458. {name:'字体颜色',col:'tfontcolor', value:(comp.kpiJson&&comp.kpiJson.tfontcolor?comp.kpiJson.tfontcolor:""), group:'数据块属性', editor:{
  459. type:'combobox',
  460. options:{data:colorJson, formatter:function(row){
  461. return "<div style=\"background-color:"+row.value+"\">"+row.text+"</div>";
  462. }}
  463. }},
  464. {name:'背景颜色',col:'bgcolor', value:(comp.bgcolor?comp.bgcolor:""), group:'数据块属性', editor:{
  465. type:'combobox',
  466. options:{data:colorJson, formatter:function(row){
  467. return "<div style=\"background-color:"+row.value+"\">"+row.text+"</div>";
  468. }}
  469. }}
  470. ]
  471. });
  472. }
  473. function editBoxData(compId){
  474. if($("#dataProperty").size() == 0){
  475. $('#Jlayout').layout('add', {region:"south", id:"dataProperty", split:false, collapsible:false,height : 100, title:'绑定数据块度量', tools:[{
  476. iconCls:'icon-cancel',
  477. handler:function(){
  478. $('#Jlayout').layout("remove", "south");
  479. }
  480. }]});
  481. }else{
  482. $('#Jlayout').layout('panel', "south").panel("setTitle", "绑定数据块度量");
  483. }
  484. //切换选项卡到立方体
  485. $("#comp_tab").tabs("select", 1);
  486. var comp = findCompById(compId);
  487. var str = "";
  488. if(!comp.kpiJson){
  489. str = "<div class=\"tipinfo\">拖拽需要展现的立方体度量到此处。</div>";
  490. }
  491. var colstr = "";
  492. var o = comp.kpiJson;
  493. if(o){
  494. colstr = "<span id=\"d_"+o.kpi_id+"\" class=\"boxcol\"><span class=\"text\">"+o.kpi_name+"</span></span>";
  495. }
  496. var ctx = "<div style=\"margin:10px;\"><div class=\"tableDatasty\" id=\"boxData\">"+str + colstr +"</div></div>";
  497. $("#dataProperty").html(ctx);
  498. //注册接收度量及维度拖放事件
  499. $("#dataProperty #boxData").droppable({
  500. accept:"#datasettree .tree-node",
  501. onDragEnter:function(e,source){
  502. var node = $("#datasettree").tree("getNode", source);
  503. var tp = node.attributes.col_type;
  504. //只能拖拽度量
  505. if(tp == 2){
  506. }else{
  507. return;
  508. }
  509. //对维度拖拽设置图标
  510. $(source).draggable('proxy').find("span").removeClass("tree-dnd-no");
  511. $(source).draggable('proxy').find("span").addClass("tree-dnd-yes");
  512. $(this).css("border", "1px solid #ff0000");
  513. e.cancelBubble=true;
  514. e.stopPropagation(); //阻止事件冒泡
  515. },
  516. onDragLeave:function(e,source){
  517. $(source).draggable('proxy').find("span").addClass("tree-dnd-no");
  518. $(source).draggable('proxy').find("span").removeClass("tree-dnd-yes");
  519. $(this).css("border", "1px dotted #666");
  520. e.cancelBubble=true;
  521. e.stopPropagation(); //阻止事件冒泡
  522. },
  523. onDrop:function(e,source){
  524. var id = compId
  525. var json = findCompById(id);
  526. e.cancelBubble=true;
  527. e.stopPropagation(); //阻止事件冒泡
  528. //清除边框颜色
  529. $(this).css("border", "1px dotted #666");
  530. //获取TREE
  531. var node = $("#datasettree").tree("getNode", source);
  532. var tp = node.attributes.col_type;
  533. //只能拖拽度量
  534. if(tp == 2){
  535. }else{
  536. msginfo("只能拖拽度量到数据块中显示。");
  537. return;
  538. }
  539. json.dsetId = node.attributes.dsetId;
  540. json.dsid = node.attributes.dsid;
  541. json.kpiJson = {"kpi_id":node.attributes.col_id, "kpi_name" : node.text, "col_name":node.attributes.col_name, "aggre":node.attributes.aggre, "fmt":node.attributes.fmt, "alias":node.attributes.alias,"tname":node.attributes.tname,"unit":node.attributes.unit,"rate":node.attributes.rate};
  542. $("#dataProperty #boxData").html("<span id=\"k_"+node.attributes.col_id+"\" class=\"boxcol\"><span class=\"text\">"+node.text+"</span></span>");
  543. //设置title
  544. comp.name = node.text;
  545. $("#c_" + comp.id + " div.ctit h5").html(comp.name);
  546. curTmpInfo.isupdate = true;
  547. boxView(comp);
  548. }
  549. });
  550. }
  551. function boxView(comp){
  552. if(!comp.kpiJson){
  553. return;
  554. }
  555. var json = {"kpiJson":comp.kpiJson, height:comp.height, "dsid":comp.dsid, "dsetId":comp.dsetId, portalParams:pageInfo.params,params:comp.params};
  556. __showLoading();
  557. $.ajax({
  558. type: "POST",
  559. url: "BoxView.action",
  560. contentType : "application/json",
  561. dataType:"html",
  562. data: JSON.stringify(json),
  563. success: function(resp){
  564. __hideLoading();
  565. $("#c_"+comp.id + " div.cctx div.ccctx").html(resp);
  566. },
  567. error:function(resp){
  568. __hideLoading();
  569. $.messager.alert('出错了','系统出错,请查看后台日志。','error');
  570. }
  571. });
  572. }
  573. function findColById(id, comp){
  574. var ret;
  575. for(i=0; i<comp.cols.length; i++){
  576. var p = comp.cols[i];
  577. if(p.id == id){
  578. ret = p;
  579. break;
  580. }
  581. }
  582. return ret;
  583. }