mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-25 06:09:55 +09:00
widget module
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@9015 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
8e20c6057e
commit
cc987e4fd6
7 changed files with 210 additions and 165 deletions
|
|
@ -1,117 +1,61 @@
|
|||
var MultiOrderManager = xe.createApp("MultiOrderManager", {
|
||||
options: null,
|
||||
values: null,
|
||||
keyObj: null,
|
||||
showObj: null,
|
||||
selectedObj: null,
|
||||
(function($){
|
||||
|
||||
init: function(key, options, values){
|
||||
var opstions = this.options = options;
|
||||
var values = this.values = values;
|
||||
var keyObj = this.keyObj = jQuery('input[name='+key+']');
|
||||
var showObj = this.showObj = keyObj.parent().find('.multiorder_show');
|
||||
var selectedObj = this.selectedObj = keyObj.parent().find('.multiorder_selected');
|
||||
xe.MultiOrderManager = xe.createApp("MultiOrderManager", {
|
||||
$keyObj: null,
|
||||
$showObj: null,
|
||||
$selectedObj: null,
|
||||
|
||||
for (var key in options){
|
||||
var option = options[key];
|
||||
var html = '<option value="'+key+'">'+option.value+'</option>';
|
||||
showObj.append(html);
|
||||
init: function(key){
|
||||
var self = this;
|
||||
var $keyObj = this.$keyObj = jQuery('input[name='+key+']');
|
||||
this.$showObj = $keyObj.parent().find('.multiorder_show');
|
||||
this.$selectedObj = $keyObj.parent().find('.multiorder_selected');
|
||||
|
||||
if (option.init){
|
||||
this.addValue(key);
|
||||
}
|
||||
}
|
||||
this.apply();
|
||||
|
||||
var thisObj = this;
|
||||
keyObj.parent().find('.multiorder_add').bind('click', function(){ thisObj.cast('MULTIORDER_ADD'); return false; });
|
||||
keyObj.parent().find('.multiorder_del').bind('click', function(){ thisObj.cast('MULTIORDER_DEL'); return false; });
|
||||
keyObj.parent().find('.multiorder_up').bind('click', function(){ thisObj.cast('MULTIORDER_UP'); return false; });
|
||||
keyObj.parent().find('.multiorder_down').bind('click', function(){ thisObj.cast('MULTIORDER_DOWN'); return false; });
|
||||
this.$showObj
|
||||
.nextAll('button')
|
||||
.filter('.multiorder_add').bind('click', function(){ self.cast('MULTIORDER_ADD'); return false; }).end()
|
||||
.filter('.multiorder_del').bind('click', function(){ self.cast('MULTIORDER_DEL'); return false; }).end()
|
||||
.filter('.multiorder_up').bind('click', function(){ self.cast('MULTIORDER_UP'); return false; }).end()
|
||||
.filter('.multiorder_down').bind('click', function(){ self.cast('MULTIORDER_DOWN'); return false; }).end()
|
||||
},
|
||||
|
||||
API_MULTIORDER_ADD: function(){
|
||||
var index = this.showObj.get(0).selectedIndex;
|
||||
if (index == -1) return;
|
||||
this.$showObj
|
||||
.find('>option:selected')
|
||||
.appendTo(this.$selectedObj);
|
||||
|
||||
if (this.addValue(index)) this.apply();
|
||||
this.refreshValue();
|
||||
},
|
||||
|
||||
API_MULTIORDER_DEL: function(){
|
||||
var index = this.selectedObj.get(0).selectedIndex;
|
||||
if (index == -1) return;
|
||||
this.$selectedObj
|
||||
.find('>option:selected[default!="true"]')
|
||||
.appendTo(this.$showObj);
|
||||
|
||||
if (this.delValue(index)) this.apply();
|
||||
this.refreshValue();
|
||||
},
|
||||
|
||||
API_MULTIORDER_UP: function(){
|
||||
var index = this.selectedObj.get(0).selectedIndex;
|
||||
if (index == -1) return;
|
||||
|
||||
if (this.up(index)) this.apply();
|
||||
var $selected = this.$selectedObj.find('>option:selected');
|
||||
$selected.eq(0).prev('option').before($selected);
|
||||
this.refreshValue();
|
||||
},
|
||||
|
||||
API_MULTIORDER_DOWN: function(){
|
||||
var index = this.selectedObj.get(0).selectedIndex;
|
||||
if (index == -1) return;
|
||||
|
||||
if (this.down(index)) this.apply();
|
||||
var $selected = this.$selectedObj.find('>option:selected');
|
||||
$selected.eq(-1).next('option').after($selected);
|
||||
this.refreshValue();
|
||||
},
|
||||
|
||||
addValue: function(index){
|
||||
var option = this.options[index];
|
||||
if (!option) return false;
|
||||
refreshValue : function() {
|
||||
var values = [];
|
||||
|
||||
if (this.values == undefined) this.values = new Array();
|
||||
for (var i in this.values){
|
||||
if (this.values[i].key == option.key) return false;
|
||||
}
|
||||
this.$selectedObj.find('>option').each(function(){
|
||||
values.push(this.value);
|
||||
});
|
||||
|
||||
this.values.push(option);
|
||||
return true;
|
||||
},
|
||||
|
||||
delValue: function(index){
|
||||
if (this.options[index].default) return false;
|
||||
|
||||
this.values.splice(index, 1);
|
||||
return true;
|
||||
},
|
||||
|
||||
up: function(index){
|
||||
if (index == 0) return false;
|
||||
|
||||
var targets = this.values.splice(index-1, 2);
|
||||
for(var i in targets){
|
||||
this.values.splice(index-1, 0, targets[i]);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
down: function(index){
|
||||
if (index == this.values.length-1) return false;
|
||||
|
||||
var targets = this.values.splice(index, 2);
|
||||
for(var i in targets){
|
||||
this.values.splice(index, 0, targets[i]);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
apply: function(){
|
||||
var keys = new Array();
|
||||
for (var i in this.values){
|
||||
keys.push(this.values[i].key);
|
||||
}
|
||||
this.keyObj.val(keys.join(','));
|
||||
|
||||
var prevValue = this.selectedObj.val();
|
||||
this.selectedObj.empty();
|
||||
for (var i in this.values){
|
||||
var option = this.values[i];
|
||||
var html = '<option value="'+option.key+'">'+option.value+'</option>';
|
||||
this.selectedObj.append(html);
|
||||
}
|
||||
this.selectedObj.val(prevValue);
|
||||
this.$keyObj.val(values.join(','));
|
||||
}
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
Loading…
Add table
Add a link
Reference in a new issue