diff --git a/build/js/ox.js b/build/js/ox.js index 93b60956..2560185a 100644 --- a/build/js/ox.js +++ b/build/js/ox.js @@ -1231,7 +1231,7 @@ Ox.formatColor = function() { }; Ox.formatCurrency = function(num, str, dec) { - return str + formatNumber(num, dec); + return str + Ox.formatNumber(num, dec); }; Ox.formatDate = function() { diff --git a/build/js/ox.ui.js b/build/js/ox.ui.js index f82f791f..7a2120dc 100644 --- a/build/js/ox.ui.js +++ b/build/js/ox.ui.js @@ -12,6 +12,7 @@ requires (function() { + // fixme: move into Ox.UI var oxui = { defaultTheme: 'classic', elements: {}, @@ -32,17 +33,6 @@ requires }; return sizes[size]; }, - jQueryFunctions: function() { - var functions = [], - $element = $('
'); - //delete $element.length; - Ox.each($element, function(k, v) { - if (typeof v == 'function') { - functions.push(k); - } - }); - return functions.sort(); - }(), path: $('script[src*=ox.ui.js]').attr('src').replace('js/ox.ui.js', ''), scrollbarSize: $.browser.mozilla ? 16 : 12, symbols: { @@ -118,11 +108,25 @@ requires ============================================================================ */ - /** - Creates an App instance. - */ Ox.App = (function() { + /*** + Ox.App + Basic application instance that communicates with a JSON API. + The JSON API should support at least the following actions: + api returns all api methods + init returns {config: {...}, user: {...}} + Options + timeout API timeout in msec + type 'GET' or 'POST' + url URL of the API + Methods + api[action] make a request + api.cancel cancel a request + launch launch the App + options get or set options + ***/ + return function(options) { options = options || {}; @@ -132,12 +136,13 @@ requires self.time = +new Date(); self.options = $.extend({ - apiTimeout: 60000, - apiType: 'POST', - apiURL: '/api/', - init: 'init' + timeout: 60000, + type: 'POST', + url: '/api/', }, options); + that.$element = new Ox.Element('body'); + function getUserAgent() { var userAgent = ''; $.each(['Chrome', 'Firefox', 'Internet Explorer', 'Opera', 'Safari'], function(i, v) { @@ -150,8 +155,6 @@ requires } function getUserData() { - //return {}; - return {}; return { navigator: { cookieEnabled: navigator.cookieEnabled, @@ -178,7 +181,7 @@ requires var counter = 0, length = data.length; data.forEach(function(src, i) { - image = new Image() + image = new Image(); image.src = oxui.path + src; image.onload = function() { (++counter == length) && callback(); @@ -194,7 +197,7 @@ requires that.api = { api: function(callback) { Ox.Request.send({ - url: self.options.apiURL, + url: self.options.url, data: { action: 'api' }, @@ -215,50 +218,52 @@ requires userAgent = getUserAgent(), userAgents = ['Chrome', 'Firefox', 'Opera', 'Safari']; $.ajaxSetup({ - timeout: self.options.apiTimeout, - type: self.options.apiType, - url: self.options.apiURL + timeout: self.options.timeour, + type: self.options.type, + url: self.options.url }); userAgents.indexOf(userAgent) > -1 ? start() : stop(); function start() { - loadImages(function() { - that.api.api(function(result) { - $.each(result.data.actions, function(key, value) { - that.api[key] = function(data, callback) { - if (arguments.length == 1 && Ox.isFunction(data)) { - callback = data; - data = {}; - } - return Ox.Request.send($.extend({ - url: self.options.apiURL, - data: { - action: key, - data: JSON.stringify(data) - }, - callback: callback - }, !value.cache ? {age: 0}: {})); - }; - }); - that.api[self.options.init](getUserData(), function(data) { - var config = data.data.config, - user = data.data.user; - document.title = config.site.name; - $(function() { - var $div = $body.find('div'); - $body.find('img').remove(); - $div.animate({ - opacity: 0 - }, 1000, function() { - $div.remove(); - }); - callback({ - config: config, - user: user - }); - }); - }); + // fixme: rename config to site? + var counter = 0, config, user; + that.api.api(function(result) { + $.each(result.data.actions, function(key, value) { + that.api[key] = function(data, callback) { + if (arguments.length == 1 && Ox.isFunction(data)) { + callback = data; + data = {}; + } + return Ox.Request.send($.extend({ + url: self.options.url, + data: { + action: key, + data: JSON.stringify(data) + }, + callback: callback + }, !value.cache ? {age: 0}: {})); + }; + }); + that.api.init(getUserData(), function(result) { + // fixme: rename config to site? + config = result.data.config, + user = result.data.user; + document.title = config.site.name; + launchCallback(); }); }); + loadImages(launchCallback); + function launchCallback() { + ++counter == 2 && $(function() { + var $div = $body.find('div'); + $body.find('img').remove(); + $div.animate({ + opacity: 0 + }, 1000, function() { + $div.remove(); + }); + callback({config: config, user: user}); + }); + } } function stop() { that.request.send(self.options.init, getUserData(), function() {}); @@ -277,6 +282,13 @@ requires }()); Ox.Clipboard = function() { + /*** + Ox.Clipboard + Basic clipboard handler + Methods + copy(data) copy data to clipboard + paste paste data from clipboard + ***/ var clipboard = {}; return { _print: function() { @@ -292,134 +304,15 @@ requires }; }(); - /** - Ox.Event event object - */ - /* - Ox.Event = function() { - var $eventHandler = $('
'), - events = {}; - function bindEvent(id, event, callback) { - Ox.print('bind', id, event); - events[id] = events[id] || {}; - events[id][event] = events[id][event] || []; - if ($.map(events[id][event], function(fn) { - return fn.toString(); - }).indexOf(callback.toString()) == -1) { - events[id][event].push(callback); - if (!isKeyboardEvent(event) || Ox.Focus.focused() == id) { - $eventHandler.bind(event + '_' + id, callback); // requestStart/requestStop currently have '' as id - } - } - } - function unbindEvent(id, event, callback) { - Ox.print('unbind', id, event); - var toString = (callback || '').toString(), - unbind = !event || (event && !isKeyboardEvent(event)) || Ox.Focus.focused() == id; - if (events[id] && (!event || events[id][event])) { - $.each(events[id], function(e, fns) { - if (!event || event == e) { - events[id][e] = $.map(events[id][e], function(fn, i) { - if (!callback || toString == fn.toString()) { - Ox.print(unbind, 'eventHandler.unbind', e, id) - unbind && $eventHandler.unbind(e + '_' + id, fn); - return null; - } else { - return fn; - } - }); - } - }); - Ox.print('id/events', id, events, events[id]) - if (!callback || (event && events[id][event].length == 0)) { - delete events[id][event]; - } - if (!event || Ox.length(events[id]) == 0) { - delete events[id]; - } - } - } - function isKeyboardEvent(event) { - return event.substr(0, 4) == 'key_'; - } - return { - _print: function() { - Ox.print(events); - }, - bind: function(id, event, callback) { - // bind event - bindEvent(id, event, callback); - }, - bindKeyboard: function(id) { - // bind all keyboard events - //Ox.print('binding', 'id', id, 'events', events[id], Ox.length(events[id]), 'keyboardevents', events[id]['keyboard']) - $.each(events[id], function(k, v) { - Ox.print('|' + k + '|'); - }) - events[id] && $.each(events[id], function(event, callbacks) { - Ox.print('BIND ID EVENT', id, event) - isKeyboardEvent(event) && $.each(callbacks, function(i, callback) { - Ox.print('bind', id, event); - $eventHandler.bind(event, callback); - }); - }); - }, - changeId: function(oldId, newId) { - // we need to reference events by options('id'), - // not by that.id, since textlist events fire on list, - // new lists have new that.ids, etc. - // so this renaming is necessary - Ox.print('changeId', oldId, newId, events[oldId]); - $.each($.extend({}, events[oldId] || {}), function(event, callbacks) { - $.each(callbacks, function(i, callback) { - Ox.Event.unbind(oldId, event, callback); - Ox.Event.bind(newId, event, callback); - }); - }); - }, - unbind: function(id, event, callback) { - // unbind event - // event and callback are optional - unbindEvent(id, event, callback); - }, - unbindAll: function() { - Ox.print('beginUnbindAll') - $.each(events, function(id, eventsById) { - $.each(eventsById, function(event, callbacks) { - $.each(callbacks, function(i, callback) { - Ox.Event.unbind(id, event, callback); - }); - }); - }); - Ox.print('endUnbindAll') - }, - trigger: function(id, event, data) { - // trigger event - // data is optional - // keyboard handler will call this with '' as id - Ox.print('trigger', id, event, data || {}); - $eventHandler.trigger(event + (id ? '_' + id : ''), data || {}); - }, - unbindKeyboard: function(id) { - // unbind all keyboard events - Ox.print('unbinding', id) - events[id] && $.each(events[id], function(event, callbacks) { - Ox.print('UNBIND ID EVENT', id, event) - isKeyboardEvent(event) && $.each(callbacks, function(i, callback) { - Ox.print('unbind', event) - $eventHandler.unbind(event, callback); - }); - }); - } - } - }(); - */ - - /** - Ox.Focus - */ - Ox.Focus = function() { + /*** + Ox.Focus + Basic focus handler + Methods + blur(id) blur element + focus(id) focus element + focused() return id of focused element, or null + ***/ var stack = []; return { _print: function() { @@ -452,20 +345,21 @@ requires }; }(); - /** + /*** Ox.History - */ + ***/ - /** + /*** Ox.Keyboard - */ + ***/ (function() { var buffer = '', bufferTime = 0, bufferTimeout = 1000, - keyNames = function() { + // wrapped in function so it can be collapsed in text editor + keyNames = (function() { return { 0: 'section', 8: 'backspace', @@ -575,7 +469,7 @@ requires 222: 'quote' // see dojo, for ex. }; - }(), + })(), modifierNames = { altKey: 'alt', // mac: option ctrlKey: 'control', @@ -611,6 +505,7 @@ requires $document.keydown(keypress); } }); + function keypress(event) { var focused = Ox.Focus.focused(), key, @@ -618,9 +513,7 @@ requires //ret = true, time; $.each(modifierNames, function(k, v) { - if (event[k]) { - keys.push(v); - } + event[k] && keys.push(v); }); // avoid pushing modifier twice //Ox.print('keys', keys) @@ -652,30 +545,37 @@ requires })(); - /** - Ox.Mouse (??) - */ + Ox.Request = function(options) { - /** - Ox.Request request object - */ - Ox.Request = function() { + /*** + Ox.Request + Basic request handler + Options + timeout + Methods + cancel() cancel request + clearCache() clear cache + options() get or set options + requests() return number of active requests + send() send request + ***/ var cache = {}, pending = {}, requests = {}, self = { - options: { + options: $.extend({ timeout: 60000, type: 'POST', - url: 'api' - } + url: '/api/' + }, options) }; return { cancel: function() { if (arguments.length == 0) { + // cancel all requests requests = {}; } else if (Ox.isFunction(arguments[0])) { // cancel with function @@ -690,7 +590,7 @@ requires } }, - emptyCache: function() { + clearCache: function() { cache = {}; }, @@ -698,11 +598,15 @@ requires return Ox.getset(self.options, options, $.noop(), this); }, + requests: function() { + return Ox.length(requests); + }, + send: function(options) { var options = $.extend({ age: -1, - callback: function() {}, + callback: null, id: Ox.uid(), timeout: self.options.timeout, type: self.options.type, @@ -713,6 +617,33 @@ requires data: options.data }); + if (pending[options.id]) { + setTimeout(function() { + Ox.Request.send(options); + }, 0); + } else { + requests[options.id] = { + url: options.url, + data: options.data + }; + if (cache[req] && (options.age == -1 || options.age > Ox.getTime() - cache[req].time)) { + setTimeout(function() { + callback && callback(cache[req].data); + }, 0); + } else { + pending[options.id] = true; + $.ajax({ + data: options.data, + dataType: 'json', + error: error, + success: success, + timeout: options.timeout, + type: options.type, + url: options.url + }); + } + } + function callback(data) { delete requests[options.id]; //Ox.length(requests) == 0 && $body.trigger('requestStop'); @@ -780,25 +711,28 @@ requires title: 'Application Error', buttons: [ new Ox.Button({ - title: 'Details' - }) - .bindEvent({ - click: function() { - $dialog.close(function() { - debug(request); - }) - } - }), + id: 'details', + title: 'Details' + }) + .bindEvent({ + click: function() { + $dialog.close(function() { + debug(request); + }); + } + }), new Ox.Button({ - title: 'Close' - }) - .bindEvent({ - click: function() { - $dialog.close(); - } - }) + id: 'close', + title: 'Close' + }) + .bindEvent({ + click: function() { + $dialog.close(); + } + }) ], content: 'Sorry, we have encountered an application error while handling your request. To help us find out what went wrong, you may want to report this error to an administrator. Otherwise, please try again later.', + keys: {enter: 'close', escape: 'close'}, width: 400, height: 200 }) @@ -822,49 +756,14 @@ requires callback(data); } - if (pending[options.id]) { - setTimeout(function() { - Ox.Request.send(options); - }, 0); - } else { - requests[options.id] = { - url: options.url, - data: options.data - }; - if (cache[req] && (options.age == -1 || options.age > Ox.getTime() - cache[req].time)) { - setTimeout(function() { - callback(cache[req].data); - }, 0); - } else { - pending[options.id] = true; - $.ajax({ - data: options.data, - dataType: 'json', - error: error, - success: success, - timeout: options.timeout, - type: options.type, - url: options.url - }); - //Ox.print('request', options.data, Ox.length(requests)); - //Ox.length(requests) == 1 && $body.trigger('requestStart'); - } - } - return options.id; - }, - - requests: function() { - return Ox.length(requests); } }; + }(); - /** - not implemented - */ Ox.Theme = function() { }; @@ -872,7 +771,7 @@ requires Ox.UI = function() { return { path: function() { - return oxui.path + return oxui.path; }, theme: function() { @@ -883,9 +782,9 @@ requires } }(); - /** + /*** Ox.URL - */ + ***/ /* ============================================================================ @@ -898,9 +797,8 @@ requires // 0, 1, 2, etc, so that append would append 0, and appendTo // would append (length - 1)? - /** - */ Ox.Container = function(options, self) { + // fixme: to be deprecated var that = new Ox.Element('div', self) .options(options || {}) .addClass('OxContainer'); @@ -911,16 +809,55 @@ requires return that; }; + Ox.jQueryElement = (function() { + // Basic jQuery element + var jQueryFunctions = (function() { + var functions = []; + Ox.each($('
'), function(key, val) { + typeof val == 'function' && functions.push(key); + }); + return functions.sort(); + })(); + return function(element) { + var that = {}; + Ox.each(jQueryFunctions, function(i, fn) { + that[fn] = function() { + var args = arguments, id, ret; + $.each(args, function(i, arg) { + // if an ox object was passed + // then pass its $element instead + // so that we can do oxObj.jqFn(oxObj) + if (arg && arg.ox) { + args[i] = arg.$element; + } + }); + ret = element.$element[fn].apply(element.$element, args); + // if the $element of an ox object was returned + // then return the ox object instead + // so that we can do oxObj.jqFn().oxFn() + /* + if (fn == 'appendTo') { + Ox.print('ret', ret, $element, ret.jquery && $elements[id = ret.data('ox')] == true) + } + */ + return ret.jquery && $elements[id = ret.data('ox')] ? + $elements[id] : ret; + }; + }); + return that; + } + })(); // check out http://ejohn.org/apps/learn/#36 (-#38, making fns work w/o new) - /** - Ox.Element - */ + Ox.Element = function() { + /*** + Basic element object + ***/ + return function(options, self) { - // construct self = self || {}; self.options = options || {}; if (!self.$eventHandler) { @@ -928,27 +865,23 @@ requires } var that = this; - // init - (function() { - // allow for Ox.Element('tagname', self) - if (typeof self.options == 'string') { - self.options = { - element: self.options - }; - } - that.ox = Ox.version; - that.id = Ox.uid(); - that.$element = $('<' + (self.options.element || 'div') + '/>', { - data: { - ox: that.id - }, - mousedown: mousedown - }); - $elements[that.id] = that; - wrapjQuery(); - })(); + // allow for Ox.Element('tagname', self) + if (typeof self.options == 'string') { + self.options = { + element: self.options + }; + } + that.ox = Ox.version; + that.id = Ox.uid(); + that.$element = $('<' + (self.options.element || 'div') + '/>', { + data: { + ox: that.id + }, + mousedown: mousedown + }); + $elements[that.id] = that; - // private + $.extend(that, Ox.jQueryElement(that)); function mousedown(e) { /* @@ -1015,78 +948,18 @@ requires } } - function wrapjQuery() { - $.each(oxui.jQueryFunctions, function(i, fn) { - that[fn] = function() { - var args = arguments, - length = args.length, - id, ret; - $.each(args, function(i, arg) { - if (Ox.isUndefined(arg)) { - Ox.print('fn', fn, 'undefined argument') - } - // if an ox object was passed - // then pass its $element instead - // so we can do oxObj.jqFn(oxObj) - if (arg && arg.ox) { - args[i] = arg.$element; - } - /* - if (arg.ox) { // fixme: or is this too much magic? - if (fn == 'appendTo' && arg.$content) { - args[i] = arg.$content - } else { - args[i] = arg.$element; - } - } - */ - }); - /* - if (fn == 'html' && that.$content) { // fixme: or is this too much magic? - $element = that.$content; - } else { - $element = that.$element; - } - */ - // why does this not work? (that?) - // ret = that.$element[fn].apply(this, arguments); - if (length == 0) { - ret = that.$element[fn](); - } else if (length == 1) { - ret = that.$element[fn](args[0]); - } else if (length == 2) { - ret = that.$element[fn](args[0], args[1]); - } else if (length == 3) { - ret = that.$element[fn](args[0], args[1], args[2]); - } else if (length == 4) { - ret = that.$element[fn](args[0], args[1], args[2], args[3]); - } - if (fn == 'data') { - // Ox.print('data ret', ret, $(ret)) - } - // if the $element of an ox object was returned - // then return the ox object instead - // so we can do oxObj.jqFn().oxFn() - return ret.jquery && $elements[id = ret.data('ox')] ? - $elements[id] : ret; - } - }); - } - - // shared self.onChange = function() { // self.onChange(key, value) // is called when an option changes // (to be implemented by widget) }; - // public - that.bindEvent = function() { - /* + /*** binds a function to an event triggered by this object - bindEvent(event, fn) or bindEvent({event0: fn0, event1: fn1, ...}) - */ + Usage + bindEvent(event, fn) or bindEvent({event0: fn0, event1: fn1, ...}) + ***/ if (arguments.length == 1) { $.each(arguments[0], function(event, fn) { // Ox.print(that.id, 'bind', event); @@ -1100,30 +973,43 @@ requires } that.defaults = function(defaults) { - /* - that.defaults({foo: x}) sets self.defaults - */ + /*** + sets the default options + Usage + that.defaults({key0: value0, key1: value1, ...}) + ***/ self.defaults = defaults; delete self.options; // fixme: hackish fix for that = Ox.Foo({...}, self).defaults({...}).options({...}) return that; }; that.gainFocus = function() { + /*** + make this object gain focus + ***/ Ox.Focus.focus(that.id); return that; }; that.hasFocus = function() { + /*** + returns true if this object has focus + ***/ return Ox.Focus.focused() == that.id; }; that.loseFocus = function() { + /*** + make this object lose focus + ***/ Ox.Focus.blur(that.id); return that; }; that.options = function() { // fixme: use Ox.getset - /* + /*** + get or set options + Usage that.options() returns self.options that.options('foo') returns self.options.foo that.options('foo', x) sets self.options.foo, @@ -1131,7 +1017,7 @@ requires that.options({foo: x, bar: y}) sets self.options.foo and self.options.bar, returns that - */ + ***/ var args, length = arguments.length, oldOptions, @@ -1162,6 +1048,9 @@ requires }; that.remove = function() { // fixme: clashes with jquery, should be removeElement + /*** + remove this element, including its event handler + ***/ that.loseFocus(); delete self.$eventHandler; that.$element.remove(); @@ -1170,10 +1059,13 @@ requires }; that.triggerEvent = function() { - /* + /*** triggers an event - triggerEvent(event) or triggerEvent(event, data) or triggerEvent({event0: data, event1: data, ...}) - */ + Usage + triggerEvent(event) + triggerEvent(event, data) + triggerEvent({event0: data0, event1: data1, ...}) + ***/ if (Ox.isObject(arguments[0])) { $.each(arguments[0], function(event, data) { if (['mousedown', 'mouserepeat', 'anyclick', 'singleclick', 'doubleclick', 'dragstart', 'drag', 'dragend', 'playing'].indexOf(event) == -1) { @@ -1191,10 +1083,12 @@ requires }; that.unbindEvent = function() { - /* - unbinds an event - unbindEvent(event, fn) or unbindEvent({event0: fn0, event1: fn1, ...}) - */ + /*** + unbinds a function from an event triggered by this element + Usage + unbindEvent(event, fn) + unbindEvent({event0: fn0, event1: fn1, ...}) + ***/ if (arguments.length == 1) { $.each(arguments[0], function(event, fn) { // Ox.print(that.id, 'unbind', arguments[0]); @@ -1207,164 +1101,12 @@ requires return that; }; - // return return that; } }(); - Ox._Element = function(element) { - var that = this; - that.def = {}; - that.opt = {}; - that.ox = Ox.version; - that.id = Ox.uid(); - //Ox.print('that.id', that.id) - that.$element = $('<' + (element || 'div') + '/>') - //.addClass('OxElement') - .data('ox', that.id); - oxui.elements[that.id] = that; - // Ox.print('oxui.elements', oxui.elements) - //function setOption() {}; - that.setOption = function() {}; - /* - */ - that.destroy = function() { - that.$element.remove(); - delete oxui.elements[that.ox]; - } - /* - */ - that.disable = function() { - - } - /* - */ - that.enable = function() { - - } - /* - */ - ///* - that.defaults = function() { - var length = arguments.length, - ret; - if (length == 0) { - ret = that.def - } else if (length == 1 && typeof arguments[0] == 'string') { - ret = that.def[arguments[0]]; - } else { - // translate ('key', 'value') to {'key': 'value'} - that.def = $.extend( - that.def, Ox.makeObject.apply(that, arguments) - ); - ret = that; - } - return ret; - } - //*/ - /* - Ox.Element.options() - get options - Ox.Element.options('foo') - get options.foo - Ox.Element.options('foo', 0) - set options.foo - Ox.Element.options({foo: 0, bar: 1}) - set options.foo and options.bar - */ - ///* - that.options = function() { - var length = arguments.length, - args, ret; - if (length == 0) { - //Ox.print('getting all options', options); - ret = that.opt; - } else if (length == 1 && typeof arguments[0] == 'string') { - //Ox.print('getting one option', options, arguments[0], options[arguments[0]]); - ret = that.opt[arguments[0]]; - } else { - // translate ('key', 'value') to {'key': 'value'} - args = Ox.makeObject.apply(that, arguments); - // if options have been set then extend options, - // otherwise extend defaults - that.opt = $.extend(Ox.length(that.opt) ? - that.opt : that.def, args); - // that.trigger('OxElement' + that.id + 'SetOptions', args); - $.each(args, function(k, v) { - that.setOption(k, v); - //Ox.print('triggering', 'OxElement' + that.id + 'SetOption', {k: v}) - //that.trigger('OxElement' + that.id + 'SetOption', {k: v}); - }) - ret = that; - } - return ret; - } - // should become self.publish - that.publish = function(event, data) { - Ox.Event.publish(event + that.id, data); - return that; - } - that.subscribe = function(event, callback) { - Ox.Event.subscribe(event, callback); - return that; - } - //that.setOptions = function() {}; - //*/ - // wrap jquery functions - // so we can do oxObj.jqFn() - $.each(oxui.jqueryFunctions, function(i, v) { - that[v] = function() { - var args = arguments, - length = args.length, - $element, id, ret; - $.each(args, function(i, v) { - // if an oxui object was passed - // then pass its $element instead - // so we can do jqObj.append(oxObj) - if (v.ox) { - args[i] = v.$element; - } - }); - if (v == 'html' && that.$content) { - $element = that.$content; - } else { - $element = that.$element; - } - // why does this not work? - // ret = that.$element[v].apply(this, arguments); - // maybe because we pass this, and not that.$element[v] ... ? - // ret = that.$element[v].apply(that.$element[v], arguments); - // doesn't work either ... - if (length == 0) { - ret = $element[v](); - } else if (length == 1) { - ret = $element[v](args[0]); - } else if (length == 2) { - ret = $element[v](args[0], args[1]); - } else if (length == 3) { - ret = $element[v](args[0], args[1], args[2]); - } else if (length == 4) { - ret = $element[v](args[0], args[1], args[2], args[3]); - } - // if the $element of an oxui object was returned - // then return the oxui object instead - // so we can do oxObj.jqFn().oxFn() - //Ox.print('v', v, 'arguments', arguments) - if (ret.jquery) { - //Ox.print('ret', ret, 'ret.data('id')', ret.data('ox')) - } - return ret.jquery && oxui.elements[id = ret.data('ox')] ? - oxui.elements[id] : ret; - } - }); - return that; - }; - - /** - Ox.Window - */ Ox.Window = function(options, self) { self = self || {}, @@ -2298,6 +2040,10 @@ requires self.$form.addItem(pos + 1, self.$conditions[pos]); } + function addGroup(pos) { + self.$form.addItem(pos + 1, constructGroup(pos)) + } + function changeConditionKey(pos, key) { Ox.print('changeConditionKey', pos, key); var oldOperator = self.options.query.conditions[pos].operator, @@ -2318,7 +2064,7 @@ requires } function changeConditionOperator(pos, operator) { - + self.options.query.conditions[pos].operator = operator; } function changeOperator(event, data) { @@ -2354,7 +2100,6 @@ requires disabled: self.options.query.conditions.length == 1, id: 'remove', title: 'remove', - tooltip: 'Remove Condition', type: 'image' }) .css({margin: '0 4px 0 8px'}) @@ -2366,7 +2111,6 @@ requires new Ox.Button({ id: 'add', title: 'add', - tooltip: 'Add Condition', type: 'image' }) .css({margin: '0 4px 0 4px'}) @@ -2377,15 +2121,14 @@ requires } }), new Ox.Button({ - id: 'more', + id: 'addgroup', title: 'more', - tooltip: 'Add Group of Conditions', type: 'image' }) .css({margin: '0 0 0 4px'}) .bindEvent({ click: function() { - + addGroup($condition.data('position') + 1) } }) ] @@ -2417,9 +2160,52 @@ requires }); } + function constructGroup() { + // fixme: duplicated + return new Ox.FormElementGroup({ + elements: [ + new Ox.Label({ + title: self.options.operator == '&' ? 'and' : 'or', + overlap: 'right', + width: 48 + }), + new Ox.FormElementGroup({ + elements: [ + new Ox.Select({ + items: $.map(self.operators, function(operator) { + Ox.print('!!!!', { + checked: operator.id != self.options.operator, + id: operator.id, + title: operator.title + }); + return { + //checked: operator.id != self.options.operator, + id: operator.id, + title: operator.title + } + }), + width: 48 + }) + .bindEvent({ + change: changeOperator + }), + new Ox.Label({ + overlap: 'left', + title: 'of the following conditions', + width: 160 + }) + ], + float: 'right', + width: 208 + }) + ], + float: 'left', + }); + } + function getConditionType(type) { type = Ox.isArray(type) ? type[0] : type; - if (['float', 'integer', 'year'].indexOf(type) > 1) { + if (['float', 'integer', 'year'].indexOf(type) > -1) { type = 'number'; } return type; @@ -7911,9 +7697,7 @@ requires position: self.options.position }); if (update) { - if (that.$element.hasClass('OxSelected')) { - $element.addClass('OxSelected'); - } + that.$element.hasClass('OxSelected') && $element.addClass('OxSelected'); that.$element.replaceWith($element); } that.$element = $element; @@ -8271,6 +8055,7 @@ requires } return value; } + //Math.random() < 0.01 && Ox.print('item', data, $item); return $item; }