You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/js/ReportGridEdit.js

373 lines
11 KiB
JavaScript

var selectedName = "";
var newHeaderArgs;
var newWidthArgs;
var newColAlignArgs;
var newColSortArgs;
var newColTypeArgs;
function $(id){
return document.getElementById(id);
}
function InitGridEdit(){
var jsonObj = null;
var selectObj = $("sel_added");
if(newHeaderArgs != null){
if(selectObj.options.length > 0)selectObj.options.length = 0;
for (var i = 0; i < newHeaderArgs.length; i++) {
if (i == 0) {
var newOption = new Option("全选框", newColSortArgs[i]);
selectObj.options.add(newOption);
}
else {
var newOption = new Option(newHeaderArgs[i], newColSortArgs[i]);
selectObj.options.add(newOption);
}
}
}else{
if(tempJson != ""){
jsonObj = eval('(' + tempJson + ')');
$("h_gridcache").value = JSON.stringify(jsonObj);
$("h_origcache").value = JSON.stringify(jsonObj);
for(var i=0;i<jsonObj.items.length;i++){
if(jsonObj.items[i].pk == 0){
if (i == 0) {
var newOption = new Option("全选框", jsonObj.items[i].name);
selectObj.options.add(newOption);
}
else {
var newOption = new Option(jsonObj.items[i].title, jsonObj.items[i].name);
selectObj.options.add(newOption);
}
}
}
}
}
}
function checkItem(itemName){
if(newHeaderArgs != null){
for(var i=0;i<newHeaderArgs.length;i++){
if (newColSortArgs[i] == itemName) {
if (i == 0) {
$("txt_title").value = "全选框";
}
else {
$("txt_title").value = newHeaderArgs[i];
}
$("txt_width").value = newWidthArgs[i];
if(parseInt(newWidthArgs[i]) == 0){
$("ck_hidden").checked = true;
}else{
$("ck_hidden").checked = false;
}
selectedName = newColSortArgs[i];
$("sel_align").value = newColAlignArgs[i];
$("dvNo").innerHTML = i;
}
}
}else{
if(tempJson != ""){
jsonObj = eval('(' + tempJson + ')');
for(var i=0;i<jsonObj.items.length;i++){
if (jsonObj.items[i].name == itemName) {
if (i == 0) {
$("txt_title").value = "全选框";
}
else {
$("txt_title").value = jsonObj.items[i].title;
}
$("txt_width").value = jsonObj.items[i].width;
if(jsonObj.items[i].width == 0){
$("ck_hidden").checked = true;
}else{
$("ck_hidden").checked = false;
}
$("sel_align").value = jsonObj.items[i].align;
$("dvNo").innerHTML = jsonObj.items[i].index;
break;
}
}
}
}
}
function itemUp(){
var addObj = $("sel_added");
var selectedArg = new Array();
if(newHeaderArgs != null){
for(var i=0;i<addObj.options.length;i++){
var iExistCount = 0;
if(addObj.options[i].selected){
if(i > 0){
selectedArg.push(addObj.options[i].value);
for(var j=iExistCount;j<newHeaderArgs.length;j++){
if(addObj.options[i].value == newColSortArgs[j]){
var title = newHeaderArgs[j-1];
var width = newWidthArgs[j-1];
var sort = newColSortArgs[j-1];
var colType = newColTypeArgs[j-1];
var align = newColAlignArgs[j-1];
//var index = i;
newHeaderArgs[j-1] = newHeaderArgs[j];
newWidthArgs[j-1] = newWidthArgs[j];
newColSortArgs[j-1] = newColSortArgs[j];
newColTypeArgs[j-1] = newColTypeArgs[j];
newColAlignArgs[j-1] = newColAlignArgs[j];
if (i == 0) {
$("txt_title").value = "全选框";
}
else {
$("txt_title").value = newHeaderArgs[j - 1];
}
$("txt_width").value = newWidthArgs[j-1];
if(parseInt(newWidthArgs[j-1]) == 0){
$("ck_hidden").checked = true;
}else{
$("ck_hidden").checked = false;
}
$("sel_align").value = newColAlignArgs[j-1];
$("dvNo").innerHTML = j-1;
newHeaderArgs[j] = title;
newWidthArgs[j] = width;
newColSortArgs[j] = sort;
newColTypeArgs[j] = colType;
newColAlignArgs[j] = align;
//var newOption = new Option(jsonObj.items[i].title,jsonObj.items[i].name);
var selText = addObj.options[i-1].text;
var selValue = addObj.options[i-1].value;
addObj.options[i-1].text = addObj.options[i].text;
addObj.options[i-1].value = addObj.options[i].value;
addObj.options[i].text = selText;
addObj.options[i].value = selValue;
addObj.options[i-1].selected = true;
addObj.options[i].selected = false;
iExistCount = j;
break;
}
}
}
}
}
}
}
function itemDown(){
var addObj = $("sel_added");
var selectedArg = new Array();
if(newHeaderArgs != null){
for(var i=0;i<addObj.options.length;i++){
var iExistCount = 0;
if(addObj.options[i].selected){
if(i <= addObj.options.length-1){
//selectedArg.push(addObj.options[i].value);
for(var j=iExistCount;j<newHeaderArgs.length;j++){
if(addObj.options[i].value == newColSortArgs[j]){
var title = newHeaderArgs[j];
var width = newWidthArgs[j];
var sort = newColSortArgs[j];
var colType = newColTypeArgs[j];
var align = newColAlignArgs[j];
//var index = i;
newHeaderArgs[j] = newHeaderArgs[j+1];
newWidthArgs[j] = newWidthArgs[j+1];
newColSortArgs[j] = newColSortArgs[j+1];
newColTypeArgs[j] = newColTypeArgs[j+1];
newColAlignArgs[j] = newColAlignArgs[j+1];
if (i == 0) {
$("txt_title").value = "全选框";
}
else {
$("txt_title").value = title;
}
$("txt_width").value = width;
if(parseInt(width) == 0){
$("ck_hidden").checked = true;
}else{
$("ck_hidden").checked = false;
}
$("sel_align").value = align;
$("dvNo").innerHTML = j+1;
newHeaderArgs[j+1] = title;
newWidthArgs[j+1] = width;
newColSortArgs[j+1] = sort;
newColTypeArgs[j+1] = colType;
newColAlignArgs[j+1] = align;
//var newOption = new Option(jsonObj.items[i].title,jsonObj.items[i].name);
var selText = addObj.options[i].text;
var selValue = addObj.options[i].value;
addObj.options[i].text = addObj.options[i+1].text;
addObj.options[i].value = addObj.options[i+1].value;
addObj.options[i+1].text = selText;
addObj.options[i+1].value = selValue;
//addObj.options[i+1].selected = true;
selectedArg.push(i+1);
addObj.options[i].selected = false;
iExistCount = j;
break;
}
}
}
}
}
for(var i=0;i<selectedArg.length;i++){
var tempIndex = parseInt(selectedArg[i]);
addObj.options[tempIndex].selected = true;
}
}
}
function checkVisible(obj){
if(obj.checked){
$("txt_width").value = "0";
$("txt_width").disabled = true;
if(newHeaderArgs != null){
for(var i=0;i<newHeaderArgs.length;i++){
if(newColSortArgs[i] == selectedName){
newWidthArgs[i] = $("txt_width").value;
}
}
}
}else{
$("txt_width").disabled = false;
$("txt_width").value = "40";
for(var i=0;i<newHeaderArgs.length;i++){
if(newColSortArgs[i] == selectedName){
newWidthArgs[i] = $("txt_width").value;
}
}
}
}
function saveState(objVal,typeName){
switch(typeName){
case "align":
for(var i=0;i<newHeaderArgs.length;i++){
if(newColSortArgs[i] == selectedName){
newColAlignArgs[i] = objVal;
}
}
break;
case "width":
for(var i=0;i<newHeaderArgs.length;i++){
if(newColSortArgs[i] == selectedName){
newWidthArgs[i] = objVal;
}
}
break;
default:
break;
}
}
function cacheAction(){
$("h_cachegrid").value = cacheGrid(" newHeaderArgs = new Array(",newHeaderArgs,");");
$("h_cachegrid").value += cacheGrid(" newWidthArgs = new Array(",newWidthArgs,");");
$("h_cachegrid").value += cacheGrid(" newColAlignArgs = new Array(",newColAlignArgs,");");
$("h_cachegrid").value += cacheGrid(" newColSortArgs = new Array(",newColSortArgs,");");
$("h_cachegrid").value += cacheGrid(" newColTypeArgs = new Array(",newColTypeArgs,");");
}
function cacheGrid(argsTitle,args,argsEnd){
var tempResult = "";
tempResult = argsTitle;
for(var i=0;i<args.length;i++){
if(i == args.length - 1){
tempResult += "\""+args[i]+"\"";
}else{
tempResult += "\""+args[i]+"\",";
}
}
tempResult += argsEnd;
return tempResult;
}
function refresh(){
//刷新父页面
//window.opener.location.href=window.opener.location.href;
window.opener.initLog();
// window.close();
}
function initJsSource(){
var jsSourceObj = null;
if($("h_scirptsource").value != ""){
jsSourceObj = eval('(' + $("h_scirptsource").value + ')');
for(var i=0;i<jsSourceObj.sources.length;i++){
getScriptObj("javascript","text/javascript",jsSourceObj.sources[i].id,true,jsSourceObj.sources[i].charset,jsSourceObj.sources[i].src);
}
}
InitGridEdit();
}
var getScriptObj = function(language,type,id,defer,charset,url){
var url = url+"?uid="+newGuid();
var loader = dhtmlxAjax.getSync(url);
var jsVal = loader.xmlDoc.responseText;
var oHead = document.getElementsByTagName('head').item(0);
var oScript = document.createElement( "script" );
oScript.language = language;
oScript.type = type;
oScript.id = id;
oScript.defer = true;
oScript.charset = charset;
oScript.text = jsVal;
oHead.appendChild(oScript);
};
function newGuid(){
var guid = "";
for (var i = 1; i <= 32; i++){
var n = Math.floor(Math.random()*16.0).toString(16);
guid += n;
if((i==8)||(i==12)||(i==16)||(i==20))
guid += "-";
}
return guid.toUpperCase();
}