Array.prototype.exchange = function (a, b) {
if (this[a] && this[b]) {
var c = this[a];
this[a] = this[b];
this[b] = c
}
return this;
}
Array.prototype.toString = function () {
var x =" = ";
var y ="\n";
var str = this[0].join(x);
for(var i = 1; i < this.length; i++){
str += y + this[i].join(x);
}
return (str);
}
var arr0 = [
["01", "01_Item"],
["02", "02_Item"],
["03", "03_Item"],
["04", "04_Item"],
["05", "05_Item"],
["06", "06_Item"],
["07", "07_Item"],
["08", "08_Item"],
["09", "09_Item"],
["10", "10_Item"],
["11", "11_Item"],
["12", "12_Item"],
["13", "13_Item"],
["14", "14_Item"],
["15", "15_Item"],
["16", "16_Item"],
["17", "17_Item"],
["18", "18_Item"],
["19", "19_Item"],
["20", "20_Item"],
];
var number = 10
var myTempElement;
var myTempPanel;
var www = new Window ("palette", "TEST");
www.orientation = "row";
var myPanel = www.add("panel");
myPanel.orientation = "row";
var myGroup = myPanel.add("group");
myGroup.orientation = "column";
for(var i = 0; i<number; i++){
myTempPanel = myGroup.add("group");
myTempPanel.orientation = "row";
myTempElement = myTempPanel.add ("edittext");
myTempElement.text = arr0[i][1];
myTempElement.size = [145, 20];
myTempElement.onChanging = function () {arr0[this.myIndex][1] = this.text};
myTempElement.myIndex = i;
myTempElement = myTempPanel.add("button");
myTempElement.text = "↑";
myTempElement.size = [20,20];
myTempElement.onClick = function(){myClick(this, -1)};
myTempElement.myIndex = i;
disable_if_zero(myTempElement);
myTempElement = myTempPanel.add("button");
myTempElement.text = "↓";
myTempElement.size = [20,20];
myTempElement.onClick = function(){myClick(this, 1)};
myTempElement.myIndex = i;
disable_if_last(myTempElement);
myTempElement = myTempPanel.add("button");
myTempElement.text = "X";
myTempElement.size = [20,20];
myTempElement.onClick = function(){myRemove(this)};
myTempElement.myIndex = i;
}
var myScrollbar = myPanel.add("scrollbar");
myScrollbar.value = 0;
myScrollbar.minvalue = 0;
myScrollbar.maxvalue = arr0.length-number;
myScrollbar.size = [20,300]
myScrollbar.helpTip = "Привет";
myScrollbar.onChanging = function(){myScroll(this)};
var myButtonGroup = www.add("group");
myButtonGroup.orientation = "column";
var myButtonOK = myButtonGroup.add ("button");
myButtonOK.text = "OK";
myButtonOK.helpTip = "Привет";
myButtonOK.onClick = function(){alert(arr0)};
var myButtonAdd = myButtonGroup.add ("button");
myButtonAdd.text = "Add";
myButtonAdd.helpTip = "Привет";
myButtonAdd.onClick = function(){myAdd(this)};
www.show();
function myScroll(current){
if (current.maxvalue <= 0){
current.visible = 0;
}
var BaseAddress = myGroup.children;
var temp;
for (var i = 0; i<BaseAddress.length; i++){
var BaseChildren = BaseAddress[i].children;
for (var b = 0; b<BaseChildren.length; b++){
temp = ~~(current.value);
if(temp < 0){temp = 0}
BaseChildren[b].myIndex = temp+i;
}
try {
BaseChildren[0].text = arr0[BaseChildren[0].myIndex][1];
BaseChildren[0].parent.visible = 1;
}catch (e){
BaseChildren[0].parent.visible = 0;
}
BaseChildren[0].active = 0;
disable_if_zero(BaseChildren[1]);
disable_if_last(BaseChildren[2]);
}
}
function disable_if_zero(ar){if (ar.myIndex == 0){ar.enabled = 0}else{ar.enabled = 1}};
function disable_if_last(ar){if (ar.myIndex == arr0.length-1){ar.enabled = 0}else{ar.enabled = 1}};
function myAdd(ar){
arr0.push(["New", "New Item"]);
var myLength = arr0.length;
//Управление скролом
if (myLength > number){
myScrollbar.visible = 1;
myScrollbar.maxvalue = (myScrollbar.maxvalue + 1);
}
myScrollbar.value = myLength;
myScrollbar.onChanging();
}
function myClick(current, ar){
arr0.exchange(current.myIndex, current.myIndex + ar);
myScrollbar.onChanging();
}
function myRemove(current){
if (current.myIndex < 0){
return
}
arr0.splice(current.myIndex,1);
//Управление скролом
if (arr0.length > number-1){
myScrollbar.maxvalue = myScrollbar.maxvalue-1;
}
myScrollbar.onChanging();
}