copy & paste

This commit is contained in:
rlx 2011-01-15 06:09:22 +00:00
parent f7b61b9907
commit bb9f04b7e8
2 changed files with 126 additions and 18 deletions

View file

@ -1597,6 +1597,17 @@ Ox.sinh = function(x) {
return (Math.exp(x) - Math.exp(-x)) / 2; return (Math.exp(x) - Math.exp(-x)) / 2;
}; };
/*
================================================================================
RegExp functions
================================================================================
*/
Ox.regexp = {
'accents': '¨´`ˆ˜',
'letters': 'a-z¨´`ˆ˜äåáàâãæçëéèèñïíìîöóòôõøœßúùûÿ'
};
/* /*
================================================================================ ================================================================================
String functions String functions

View file

@ -275,6 +275,22 @@ requires
}(); }();
Ox.Clipboard = function() {
var clipboard = {};
return {
_print: function() {
Ox.print(JSON.stringify(clipboard));
},
copy: function(data) {
clipboard = data;
Ox.print('copy', JSON.stringify(clipboard));
},
paste: function(type) {
return clipboard;
}
};
}();
/** /**
Ox.Event event object Ox.Event event object
*/ */
@ -413,8 +429,6 @@ requires
if (index > -1 && index == stack.length - 1) { if (index > -1 && index == stack.length - 1) {
stack.length == 1 ? stack.pop() : stack.length == 1 ? stack.pop() :
stack.splice(stack.length - 2, 0, stack.pop()); stack.splice(stack.length - 2, 0, stack.pop());
// fix later: Ox.Event.unbindKeyboard($elements[id].options('id'));
// fix later: stack.length && Ox.Event.bindKeyboard($elements[stack[stack.length - 1]].options('id'));
//$elements[id].removeClass('OxFocus'); //$elements[id].removeClass('OxFocus');
$('.OxFocus').removeClass('OxFocus'); // fixme: the above is better, and should work $('.OxFocus').removeClass('OxFocus'); // fixme: the above is better, and should work
stack.length && $elements[stack[stack.length - 1]].addClass('OxFocus'); stack.length && $elements[stack[stack.length - 1]].addClass('OxFocus');
@ -424,10 +438,8 @@ requires
focus: function(id) { focus: function(id) {
var index = stack.indexOf(id); var index = stack.indexOf(id);
if (index == -1 || index < stack.length - 1) { if (index == -1 || index < stack.length - 1) {
// fix later: stack.length && Ox.Event.unbindKeyboard($elements[stack[stack.length - 1]].options('id'));
index > -1 && stack.splice(index, 1); index > -1 && stack.splice(index, 1);
stack.push(id); stack.push(id);
// fix later: Ox.Event.bindKeyboard($elements[id].options('id'));
$('.OxFocus').removeClass('OxFocus'); // fixme: see above $('.OxFocus').removeClass('OxFocus'); // fixme: see above
$elements[id].addClass('OxFocus'); $elements[id].addClass('OxFocus');
Ox.print('focus', id, stack); Ox.print('focus', id, stack);
@ -2587,6 +2599,7 @@ requires
.bindEvent($.extend(self.options.type == 'textarea' ? {} : { .bindEvent($.extend(self.options.type == 'textarea' ? {} : {
key_enter: submit key_enter: submit
}, { }, {
key_control_v: paste,
key_escape: cancel key_escape: cancel
})); }));
@ -3088,6 +3101,11 @@ requires
} }
} }
function paste() {
var data = Ox.Clipboard.paste();
data.text && self.$input.val(data.text);
}
function selectMenu(event, data) { function selectMenu(event, data) {
var pos = cursor(); var pos = cursor();
//Ox.print('selectMenu', pos) //Ox.print('selectMenu', pos)
@ -3159,7 +3177,7 @@ requires
} else if (key == 'placeholder') { } else if (key == 'placeholder') {
setPlaceholder(); setPlaceholder();
} else if (key == 'value') { } else if (key == 'value') {
val = self.$input.val(); val = self.$input.val(); // fixme: ??
self.$input.val(value); self.$input.val(value);
setPlaceholder(); setPlaceholder();
} else if (key == 'width') { } else if (key == 'width') {
@ -5887,6 +5905,8 @@ requires
self.onChange = function(key, value) { self.onChange = function(key, value) {
if (key == 'request') { if (key == 'request') {
that.$element.options(key, value); that.$element.options(key, value);
} else if (key == 'paste') {
that.$element.options(key, value);
} else if (key == 'selected') { } else if (key == 'selected') {
that.$element.options(key, value); that.$element.options(key, value);
} }
@ -5896,13 +5916,23 @@ requires
that.$element.closePreview(); that.$element.closePreview();
}; };
that.paste = function(data) {
that.$element.paste(data);
return that;
};
that.reloadList = function() {
that.$element.reloadList();
return that;
};
that.scrollToSelection = function() { that.scrollToSelection = function() {
that.$element.scrollToSelection(); that.$element.scrollToSelection();
}; };
that.size = function() { that.size = function() {
that.$element.size(); that.$element.size();
} };
that.sortList = function(key, operator) { that.sortList = function(key, operator) {
self.options.sort = [{ self.options.sort = [{
@ -5911,6 +5941,18 @@ requires
}]; }];
updateKeys(); updateKeys();
that.$element.sortList(key, operator); that.$element.sortList(key, operator);
};
that.value = function(id, key, value) {
// fixme: make this accept id, {k: v, ...}
if (arguments.length == 1) {
return that.$element.value(id);
} else if (arguments.length == 2) {
return that.$element.value(id, key);
} else {
that.$element.value(id, key, value);
return that;
}
} }
return that; return that;
@ -6110,7 +6152,10 @@ requires
ids: [], ids: [],
itemMargin: self.options.type == 'text' ? 0 : 8, // 2 x 4 px margin ... fixme: the 2x should be computed later itemMargin: self.options.type == 'text' ? 0 : 8, // 2 x 4 px margin ... fixme: the 2x should be computed later
keyboardEvents: { keyboardEvents: {
key_backspace: deleteItems, key_control_c: copyItems,
key_control_n: addItem,
key_control_v: pasteItems,
key_control_x: cutItems,
key_delete: deleteItems, key_delete: deleteItems,
key_end: scrollToFirst, key_end: scrollToFirst,
key_enter: open, key_enter: open,
@ -6230,6 +6275,10 @@ requires
} }
} }
function addItem() {
that.triggerEvent('add', {});
}
function addNextToSelection() { function addNextToSelection() {
var pos = getNext(); var pos = getNext();
if (pos > -1) { if (pos > -1) {
@ -6289,6 +6338,27 @@ requires
return $page; return $page;
} }
function copyItems() {
var ids = getSelectedIds();
ids.length && that.triggerEvent('copy', {
ids: ids
});
/*
ids.length && self.options.copy && Ox.Clipboard.copy(
self.options.copy(
$.map(ids, function(id) {
return that.value(id);
})
)
);
*/
}
function cutItems() {
copyItems();
deleteItems();
}
function deleteItems() { function deleteItems() {
var ids = getSelectedIds(); var ids = getSelectedIds();
ids.length && that.triggerEvent('delete', { ids.length && that.triggerEvent('delete', {
@ -6750,6 +6820,10 @@ requires
}); });
} }
function pasteItems() {
that.triggerEvent('paste', Ox.Clipboard.paste());
}
function preview() { function preview() {
var ids = getSelectedIds(); var ids = getSelectedIds();
if (ids.length) { if (ids.length) {
@ -6880,9 +6954,8 @@ requires
} }
function selectAll() { function selectAll() {
$.each(Ox.range(self.listLength), function(i, v) { Ox.range(self.listLength).forEach(function(pos) {
//Ox.print('adding', v); addToSelection(pos);
addToSelection(v);
}); });
} }
@ -7075,10 +7148,15 @@ requires
return that; return that;
}; };
that.paste = function(data) {
pasteItems(data);
return that;
};
that.reloadList = function() { that.reloadList = function() {
updateQuery(); updateQuery();
return that; return that;
} };
that.reloadPages = function() { that.reloadPages = function() {
//Ox.print('---------------- list reload, page', self.page) //Ox.print('---------------- list reload, page', self.page)
@ -7155,7 +7233,9 @@ requires
$item = self.$items[pos], $item = self.$items[pos],
data = $item.options('data'), data = $item.options('data'),
oldValue; oldValue;
if (arguments.length == 2) { if (arguments.length == 1) {
return data;
} else if (arguments.length == 2) {
return data[key]; return data[key];
} else { } else {
oldValue = data[key]; oldValue = data[key];
@ -7270,12 +7350,15 @@ requires
$.extend(self, { $.extend(self, {
columnPositions: [], columnPositions: [],
defaultColumnWidths: $.map(self.options.columns, function(v) {
return v.width;
}),
itemHeight: 16, itemHeight: 16,
page: 0, page: 0,
pageLength: 100, pageLength: 100,
scrollLeft: 0, scrollLeft: 0,
selectedColumn: getColumnIndexById(self.options.sort[0].key), selectedColumn: getColumnIndexById(self.options.sort[0].key),
visibleColumns: $.map(self.options.columns, function(v, i) { visibleColumns: $.map(self.options.columns, function(v) {
return v.visible ? v : null; return v.visible ? v : null;
}) })
}); });
@ -7342,6 +7425,7 @@ requires
max: self.options.max, max: self.options.max,
min: self.options.min, min: self.options.min,
pageLength: self.options.pageLength, pageLength: self.options.pageLength,
paste: self.options.paste,
orientation: 'vertical', orientation: 'vertical',
request: self.options.request, request: self.options.request,
selected: self.options.selected, selected: self.options.selected,
@ -7495,7 +7579,10 @@ requires
}); });
}) })
.dblclick(function() { .dblclick(function() {
resizeColumn(v.id, v.width); Ox.print('dblclick')
resizeColumn(
v.id, self.defaultColumnWidths[getColumnIndexById(v.id)]
);
}); });
} }
$left = $('<div>').addClass('OxLeft').appendTo($resize); $left = $('<div>').addClass('OxLeft').appendTo($resize);
@ -7610,7 +7697,7 @@ requires
} }
function getCell(id, key) { function getCell(id, key) {
//Ox.print('getCell', id, key) Ox.print('getCell', id, key)
var $item = getItem(id); var $item = getItem(id);
return $($item.find('.OxCell.OxColumn' + Ox.toTitleCase(key))[0]); return $($item.find('.OxCell.OxColumn' + Ox.toTitleCase(key))[0]);
} }
@ -7708,6 +7795,7 @@ requires
} }
function resizeColumn(id, width) { function resizeColumn(id, width) {
Ox.print('resizeColumn', id, width)
var i = getColumnIndexById(id), var i = getColumnIndexById(id),
pos = getColumnPositionById(id); pos = getColumnPositionById(id);
self.options.columns[i].width = width; self.options.columns[i].width = width;
@ -7765,6 +7853,8 @@ requires
if (key == 'request') { if (key == 'request') {
//alert('request set!!') //alert('request set!!')
that.$body.options(key, value); that.$body.options(key, value);
} else if (key == 'paste') {
that.$body.options(key, value);
} else if (key == 'selected') { } else if (key == 'selected') {
that.$body.options(key, value); that.$body.options(key, value);
} }
@ -7831,6 +7921,11 @@ requires
return that; return that;
} }
that.paste = function(data) {
that.$body.paste();
return that;
};
that.reloadList = function() { that.reloadList = function() {
that.$body.reloadList(); that.$body.reloadList();
return that; return that;
@ -7870,9 +7965,11 @@ requires
that.value = function(id, key, value) { that.value = function(id, key, value) {
// fixme: make this accept id, {k: v, ...} // fixme: make this accept id, {k: v, ...}
var $item = getItem(id), var $item = getItem(id),
$cell = getCell(id, key), //$cell = getCell(id, key),
column = self.options.columns[getColumnIndexById(key)]; column = self.options.columns[getColumnIndexById(key)];
if (arguments.length == 2) { if (arguments.length == 1) {
return that.$body.value(id);
} else if (arguments.length == 2) {
return that.$body.value(id, key); return that.$body.value(id, key);
} else { } else {
that.$body.value(id, key, value); that.$body.value(id, key, value);
@ -9497,7 +9594,7 @@ requires
$title.html(self.options.title); $title.html(self.options.title);
} }
}; };
that.update = function() { that.update = function() { // fixme: used anywhere?
self.options.collapsed && that.$content.css({ self.options.collapsed && that.$content.css({
marginTop: -that.$content.height() marginTop: -that.$content.height()
}); });