From bb9f04b7e82980d81820965152663d2e319603a2 Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Sat, 15 Jan 2011 06:09:22 +0000 Subject: [PATCH] copy & paste --- build/js/ox.js | 11 ++++ build/js/ox.ui.js | 133 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 126 insertions(+), 18 deletions(-) diff --git a/build/js/ox.js b/build/js/ox.js index 115c0667..17288070 100644 --- a/build/js/ox.js +++ b/build/js/ox.js @@ -1597,6 +1597,17 @@ Ox.sinh = function(x) { return (Math.exp(x) - Math.exp(-x)) / 2; }; +/* +================================================================================ +RegExp functions +================================================================================ +*/ + +Ox.regexp = { + 'accents': '¨´`ˆ˜', + 'letters': 'a-z¨´`ˆ˜äåáàâãæçëéèèñïíìîöóòôõøœßúùûÿ' +}; + /* ================================================================================ String functions diff --git a/build/js/ox.ui.js b/build/js/ox.ui.js index 54196f0a..c93f5a16 100644 --- a/build/js/ox.ui.js +++ b/build/js/ox.ui.js @@ -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 */ @@ -413,8 +429,6 @@ requires if (index > -1 && index == stack.length - 1) { stack.length == 1 ? 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'); $('.OxFocus').removeClass('OxFocus'); // fixme: the above is better, and should work stack.length && $elements[stack[stack.length - 1]].addClass('OxFocus'); @@ -424,10 +438,8 @@ requires focus: function(id) { var index = stack.indexOf(id); 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); stack.push(id); - // fix later: Ox.Event.bindKeyboard($elements[id].options('id')); $('.OxFocus').removeClass('OxFocus'); // fixme: see above $elements[id].addClass('OxFocus'); Ox.print('focus', id, stack); @@ -2587,6 +2599,7 @@ requires .bindEvent($.extend(self.options.type == 'textarea' ? {} : { key_enter: submit }, { + key_control_v: paste, 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) { var pos = cursor(); //Ox.print('selectMenu', pos) @@ -3159,7 +3177,7 @@ requires } else if (key == 'placeholder') { setPlaceholder(); } else if (key == 'value') { - val = self.$input.val(); + val = self.$input.val(); // fixme: ?? self.$input.val(value); setPlaceholder(); } else if (key == 'width') { @@ -5887,6 +5905,8 @@ requires self.onChange = function(key, value) { if (key == 'request') { that.$element.options(key, value); + } else if (key == 'paste') { + that.$element.options(key, value); } else if (key == 'selected') { that.$element.options(key, value); } @@ -5896,13 +5916,23 @@ requires 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.$element.scrollToSelection(); }; that.size = function() { that.$element.size(); - } + }; that.sortList = function(key, operator) { self.options.sort = [{ @@ -5911,6 +5941,18 @@ requires }]; updateKeys(); 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; @@ -6110,7 +6152,10 @@ requires ids: [], itemMargin: self.options.type == 'text' ? 0 : 8, // 2 x 4 px margin ... fixme: the 2x should be computed later keyboardEvents: { - key_backspace: deleteItems, + key_control_c: copyItems, + key_control_n: addItem, + key_control_v: pasteItems, + key_control_x: cutItems, key_delete: deleteItems, key_end: scrollToFirst, key_enter: open, @@ -6230,6 +6275,10 @@ requires } } + function addItem() { + that.triggerEvent('add', {}); + } + function addNextToSelection() { var pos = getNext(); if (pos > -1) { @@ -6289,6 +6338,27 @@ requires 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() { var ids = getSelectedIds(); ids.length && that.triggerEvent('delete', { @@ -6750,6 +6820,10 @@ requires }); } + function pasteItems() { + that.triggerEvent('paste', Ox.Clipboard.paste()); + } + function preview() { var ids = getSelectedIds(); if (ids.length) { @@ -6880,9 +6954,8 @@ requires } function selectAll() { - $.each(Ox.range(self.listLength), function(i, v) { - //Ox.print('adding', v); - addToSelection(v); + Ox.range(self.listLength).forEach(function(pos) { + addToSelection(pos); }); } @@ -7075,10 +7148,15 @@ requires return that; }; + that.paste = function(data) { + pasteItems(data); + return that; + }; + that.reloadList = function() { updateQuery(); return that; - } + }; that.reloadPages = function() { //Ox.print('---------------- list reload, page', self.page) @@ -7155,7 +7233,9 @@ requires $item = self.$items[pos], data = $item.options('data'), oldValue; - if (arguments.length == 2) { + if (arguments.length == 1) { + return data; + } else if (arguments.length == 2) { return data[key]; } else { oldValue = data[key]; @@ -7270,12 +7350,15 @@ requires $.extend(self, { columnPositions: [], + defaultColumnWidths: $.map(self.options.columns, function(v) { + return v.width; + }), itemHeight: 16, page: 0, pageLength: 100, scrollLeft: 0, 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; }) }); @@ -7342,6 +7425,7 @@ requires max: self.options.max, min: self.options.min, pageLength: self.options.pageLength, + paste: self.options.paste, orientation: 'vertical', request: self.options.request, selected: self.options.selected, @@ -7495,7 +7579,10 @@ requires }); }) .dblclick(function() { - resizeColumn(v.id, v.width); + Ox.print('dblclick') + resizeColumn( + v.id, self.defaultColumnWidths[getColumnIndexById(v.id)] + ); }); } $left = $('