From f43122f795cb8e275d06288299b5ced3ce8b5b98 Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Tue, 11 Oct 2011 11:22:16 +0000 Subject: [PATCH] workaround for select values not getting updated correctly when updating form values --- source/Ox.UI/js/Calendar/Ox.ListCalendar.js | 54 ++++++++++++--------- source/Ox.UI/js/Form/Ox.Form.js | 1 + source/Ox.UI/js/Form/Ox.Select.js | 6 ++- source/Ox.UI/js/Window/Ox.Dialog.js | 2 + 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/source/Ox.UI/js/Calendar/Ox.ListCalendar.js b/source/Ox.UI/js/Calendar/Ox.ListCalendar.js index 7b7b60c4..1b44358b 100644 --- a/source/Ox.UI/js/Calendar/Ox.ListCalendar.js +++ b/source/Ox.UI/js/Calendar/Ox.ListCalendar.js @@ -484,7 +484,7 @@ Ox.ListCalendar = function(options, self) { selectEvent(event); self.$nameInput.focusInput(); } else { - alert(result.status.code) + alert(result.status.text); } }); } @@ -495,22 +495,26 @@ Ox.ListCalendar = function(options, self) { data = {id: id}; data[key] = value; self.options.editEvent(data, function(result) { - self.options.events[index][key] = value; - self.$list.value(id, key, value); - if (['name', 'type', 'start', 'end'].indexOf(key) > -1) { - self.$calendar.editEvent(id, key, value); - } - if (key == 'name') { - self.$eventName.options({title: value}); - } else if (['start', 'end'].indexOf(key) > -1) { - self.$durationInput.options({ - value: Ox.formatDateRangeDuration( - self.$startInput.options('value'), - self.$endInput.options('value') - || Ox.formatDate(new Date(), '%Y-%m-%d %H%:%M:%S'), - true - ) - }); + if (result.status.code == 200) { + self.options.events[index][key] = value; + self.$list.value(id, key, value); + if (['name', 'type', 'start', 'end'].indexOf(key) > -1) { + self.$calendar.editEvent(id, key, value); + } + if (key == 'name') { + self.$eventName.options({title: value}); + } else if (['start', 'end'].indexOf(key) > -1) { + self.$durationInput.options({ + value: Ox.formatDateRangeDuration( + self.$startInput.options('value'), + self.$endInput.options('value') + || Ox.formatDate(new Date(), '%Y-%m-%d %H%:%M:%S'), + true + ) + }); + } + } else { + alert(result.status.text); } }); } @@ -546,12 +550,16 @@ Ox.ListCalendar = function(options, self) { var id = self.selectedEvent, index = Ox.getPositionById(self.options.events, id); self.options.removeEvent({id: id}, function(result) { - self.options.events.splice(index, 1); - var time0 = +new Date(); - self.$list.options({items: Ox.clone(self.options.events, true)}); - Ox.print('TIME TO SET LIST OPTIONS:', +new Date() - time0); - self.$calendar.removeEvent(); - selectEvent({}); + if (result.status.code == '200') { + self.options.events.splice(index, 1); + var time0 = +new Date(); + self.$list.options({items: Ox.clone(self.options.events, true)}); + Ox.print('TIME TO SET LIST OPTIONS:', +new Date() - time0); + self.$calendar.removeEvent(); + selectEvent({}); + } else { + alert(result.status.text); + } }); } diff --git a/source/Ox.UI/js/Form/Ox.Form.js b/source/Ox.UI/js/Form/Ox.Form.js index dd713141..bd6635bf 100644 --- a/source/Ox.UI/js/Form/Ox.Form.js +++ b/source/Ox.UI/js/Form/Ox.Form.js @@ -138,6 +138,7 @@ Ox.Form = function(options, self) { //Ox.print('VALUES', values) return values; } else { + Ox.print('SET FORM VALUES', arguments[0]) Ox.forEach(arguments[0], function(value, key) { var index = getItemIndexById(key); //index > -1 && Ox.print(':::::::', key, value) diff --git a/source/Ox.UI/js/Form/Ox.Select.js b/source/Ox.UI/js/Form/Ox.Select.js index c115aad6..e13f2472 100644 --- a/source/Ox.UI/js/Form/Ox.Select.js +++ b/source/Ox.UI/js/Form/Ox.Select.js @@ -43,11 +43,12 @@ Ox.Select = function(options, self) { size: 'medium', title: '', type: 'text', // can be 'text' or 'image' - value: [], + value: '', width: 'auto' }) // fixme: make default selection restorable // or allow for extra action items below options + // fixme: passing value has no effect .options(options) .addClass( 'OxSelect Ox' + Ox.toTitleCase(self.options.size) + ( @@ -148,6 +149,7 @@ Ox.Select = function(options, self) { function changeMenu(data) { //Ox.print('clickMenu: ', self.options.id, data) self.checked = self.optionGroup.checked(); + self.options.value = data.checked[0].id; self.$title && self.$title.html( self.options.title ? self.options.title : data.checked[0].title @@ -182,6 +184,8 @@ Ox.Select = function(options, self) { } }; + // FIXME: selected() _and_ selectItem() _and_ value() ??? + /*@ selected gets selected item () -> returns object of selected items with id, title diff --git a/source/Ox.UI/js/Window/Ox.Dialog.js b/source/Ox.UI/js/Window/Ox.Dialog.js index aced2e53..a106d0ae 100644 --- a/source/Ox.UI/js/Window/Ox.Dialog.js +++ b/source/Ox.UI/js/Window/Ox.Dialog.js @@ -335,10 +335,12 @@ Ox.Dialog = function(options, self) { left: left, top: top }), animate); + /* that.triggerEvent('resize', { width: self.options.width, height: self.options.height }); + */ } function resizestart(event) {