use new form element syntax

This commit is contained in:
rolux 2011-12-21 21:04:28 +05:30
parent 6321b4e2a9
commit e965ae21c2
15 changed files with 123 additions and 126 deletions

View file

@ -284,11 +284,10 @@ pandora.ui.accountForm = function(action, value) {
}) })
.bindEvent({ .bindEvent({
change: function(data) { change: function(data) {
var selected = data.selected[0].id;
pandora.$ui.usernameOrEmailInput.options({ pandora.$ui.usernameOrEmailInput.options({
autovalidate: selected == 'username' autovalidate: data.value == 'username'
? pandora.autovalidateUsername : pandora.autovalidateEmail, ? pandora.autovalidateUsername : pandora.autovalidateEmail,
validate: pandora.validateUser(selected, true), validate: pandora.validateUser(data.value, true),
value: '' value: ''
}).focusInput(true); }).focusInput(true);
that.$element.find('.OxFormMessage:visible').html('').hide(); that.$element.find('.OxFormMessage:visible').html('').hide();

View file

@ -83,7 +83,7 @@ pandora.ui.contactForm = function() {
.bindEvent({ .bindEvent({
change: function(data) { change: function(data) {
$receiptCheckbox.options({ $receiptCheckbox.options({
title: data.checked title: data.value
? 'Send a receipt to ' + pandora.user.email ? 'Send a receipt to ' + pandora.user.email
: 'Don\'t send me a receipt' : 'Don\'t send me a receipt'
}); });

View file

@ -271,7 +271,7 @@ pandora.ui.filesView = function(options, self) {
conditions = [{key: 'id', value: data.value, operator: '=='}] conditions = [{key: 'id', value: data.value, operator: '=='}]
} else { } else {
conditions = Ox.map(['title', 'director', 'year'], function(key) { conditions = Ox.map(['title', 'director', 'year'], function(key) {
var value = self['$' + key + 'Input'].options('value') var value = self['$' + key + 'Input'].value()
return value.length ? {key: key, value: value, operator: '='} : null; return value.length ? {key: key, value: value, operator: '='} : null;
}); });
} }
@ -286,7 +286,7 @@ pandora.ui.filesView = function(options, self) {
*/ */
conditions = {}; conditions = {};
Ox.map(['id', 'title', 'director', 'year'], function(key) { Ox.map(['id', 'title', 'director', 'year'], function(key) {
var value = self['$' + key + 'Input'].options('value'); var value = self['$' + key + 'Input'].value();
if(value.length) { if(value.length) {
conditions[key] = key == 'director' ? value.split(', ') : value; conditions[key] = key == 'director' ? value.split(', ') : value;
} }
@ -295,18 +295,18 @@ pandora.ui.filesView = function(options, self) {
var length = result.data.items.length; var length = result.data.items.length;
if (length == 0) { if (length == 0) {
if (key != 'id') { if (key != 'id') {
self.$idInput.options({value: ''}); self.$idInput.value('');
} }
} else if (result.data.items.length == 1) { } else if (result.data.items.length == 1) {
['title', 'director', 'year', 'id'].forEach(function(key) { ['title', 'director', 'year', 'id'].forEach(function(key) {
self['$' + key + 'Input'].options({ self['$' + key + 'Input'].value(
value: key == 'director' key == 'director'
? result.data.items[0][key].join(', ') ? result.data.items[0][key].join(', ')
: result.data.items[0][key] : result.data.items[0][key]
}); );
}); });
} else { } else {
self.$idInput.options({value: ''}); self.$idInput.value('');
} }
}); });
} }
@ -343,7 +343,7 @@ pandora.ui.filesView = function(options, self) {
.bindEvent({ .bindEvent({
click: function() { click: function() {
['title', 'director', 'year', 'id'].forEach(function(key) { ['title', 'director', 'year', 'id'].forEach(function(key) {
self['$' + key + 'Input'].options({value: ''}) self['$' + key + 'Input'].value('');
}); });
} }
}); });
@ -421,11 +421,11 @@ pandora.ui.filesView = function(options, self) {
}, function(result) { }, function(result) {
['title', 'director', 'year'].forEach(function(key) { ['title', 'director', 'year'].forEach(function(key) {
if (result.data[key]) { if (result.data[key]) {
self['$' + key + 'Input'].options({ self['$' + key + 'Input'].value(
value: key == 'director' key == 'director'
? result.data[key].join(', ') ? result.data[key].join(', ')
: result.data[key] : result.data[key]
}); );
} }
}); });
updateForm(); updateForm();

View file

@ -171,7 +171,7 @@ pandora.ui.filter = function(id) {
.bindEvent('change', function(data) { .bindEvent('change', function(data) {
var filters = Ox.clone(pandora.user.ui.filters), var filters = Ox.clone(pandora.user.ui.filters),
find, find,
id_ = data.selected[0].id, id_ = data.value,
i_ = Ox.getPositionById(pandora.user.ui.filters, id_); i_ = Ox.getPositionById(pandora.user.ui.filters, id_);
if (i_ == -1) { if (i_ == -1) {
// new filter was not part of old filter set // new filter was not part of old filter set

View file

@ -16,7 +16,6 @@ pandora.ui.findElement = function() {
}) })
.bindEvent({ .bindEvent({
change: function(data) { change: function(data) {
var key = data.selected[0].id;
pandora.$ui.findInput.options({ pandora.$ui.findInput.options({
autocomplete: autocompleteFunction() autocomplete: autocompleteFunction()
}).focusInput(true); }).focusInput(true);
@ -46,8 +45,7 @@ pandora.ui.findElement = function() {
}) })
.bindEvent({ .bindEvent({
change: function(data) { change: function(data) {
var key = data.selected[0].id; if (data.value == 'advanced') {
if (key == 'advanced') {
that.update(); that.update();
pandora.$ui.filterDialog = pandora.ui.filterDialog().open(); pandora.$ui.filterDialog = pandora.ui.filterDialog().open();
} else { } else {

View file

@ -7,36 +7,36 @@ pandora.ui.folderBrowserBar = function(id) {
pandora.$ui.findListElement[id] = Ox.FormElementGroup({ pandora.$ui.findListElement[id] = Ox.FormElementGroup({
elements: [ elements: [
pandora.$ui.findListSelect[id] = Ox.Select({ pandora.$ui.findListSelect[id] = Ox.Select({
items: [ items: [
{id: 'user', title: 'Find: User', checked: true}, {id: 'user', title: 'Find: User', checked: true},
{id: 'list', title: 'Find: List'} {id: 'list', title: 'Find: List'}
], ],
overlap: 'right', overlap: 'right',
type: 'image' type: 'image'
}) })
.bindEvent({ .bindEvent({
change: function(data) { change: function(data) {
var key = data.selected[0].id == 'user' ? 'user' : 'name', var key = data.value == 'user' ? 'user' : 'name',
value = pandora.$ui.findListInput[id].value(); value = pandora.$ui.findListInput[id].value();
value && updateList(key, value); value && updateList(key, value);
pandora.$ui.findListInput[id].options({ pandora.$ui.findListInput[id].options({
placeholder: data.selected[0].title placeholder: data.title
}); });
} }
}), }),
pandora.$ui.findListInput[id] = Ox.Input({ pandora.$ui.findListInput[id] = Ox.Input({
changeOnKeypress: true, changeOnKeypress: true,
clear: true, clear: true,
placeholder: 'Find: User', placeholder: 'Find: User',
width: pandora.getFoldersWidth() - 24 width: pandora.getFoldersWidth() - 24
}) })
.bindEvent({ .bindEvent({
change: function(data) { change: function(data) {
var key = pandora.$ui.findListSelect[id].value() == 'user' ? 'user' : 'name', var key = pandora.$ui.findListSelect[id].value() == 'user' ? 'user' : 'name',
value = data.value; value = data.value;
updateList(key, value); updateList(key, value);
} }
}) })
], ],
}) })
.css({ .css({

View file

@ -107,8 +107,8 @@ pandora.ui.home = function() {
var folder = pandora.getListData().folder, var folder = pandora.getListData().folder,
value = $findInput.value(); value = $findInput.value();
folder && pandora.$ui.folderList[folder].options({selected: []}); folder && pandora.$ui.folderList[folder].options({selected: []});
pandora.$ui.findSelect.options({value: '*'}); pandora.$ui.findSelect.value('*');
pandora.$ui.findInput.options({value: value}); pandora.$ui.findInput.value(value);
that.fadeOutScreen(); that.fadeOutScreen();
pandora.UI.set('find', { pandora.UI.set('find', {
conditions: value === '' conditions: value === ''

View file

@ -55,7 +55,7 @@ pandora.ui.listDialog = function(section) {
.bindEvent({ .bindEvent({
change: function(data) { change: function(data) {
pandora.$ui.findIconItemInput.options({ pandora.$ui.findIconItemInput.options({
placeholder: data.selected[0].title placeholder: data.title
}); });
// fixme: this is a bit weird // fixme: this is a bit weird
setTimeout(function() { setTimeout(function() {
@ -247,13 +247,13 @@ pandora.ui.listGeneralPanel = function(listData) {
} }
} }
function editStatus(data) { function editStatus(data) {
var status = data.selected[0].id; var status = data.value;
$statusSelect.value(status == 'private' ? 'public' : 'private'); $statusSelect.value(status == 'private' ? 'public' : 'private');
pandora.changeListStatus(listData.id, status, function(result) { pandora.changeListStatus(listData.id, status, function(result) {
listData.status = result.data.status; listData.status = result.data.status;
if (result.data.status == 'private') { if (result.data.status == 'private') {
subscribers = 0; subscribers = 0;
$subscribersInput.options({value: 0}); $subscribersInput.value(0);
} }
$statusSelect.value(result.data.status); $statusSelect.value(result.data.status);
$subscribersInput[getSubscribersAction()](); $subscribersInput[getSubscribersAction()]();

View file

@ -19,11 +19,11 @@ pandora.ui.logsDialog = function() {
}) })
.bindEvent({ .bindEvent({
change: function(data) { change: function(data) {
var key = data.selected[0].id, var key = data.value,
value = $findInput.value(); value = $findInput.value();
value && updateList(key, value); value && updateList(key, value);
$findInput.options({ $findInput.options({
placeholder: data.selected[0].title placeholder: data.title
}); });
} }
}), }),

View file

@ -162,7 +162,7 @@ pandora.ui.mainMenu = function() {
that.checkItem('allitems'); that.checkItem('allitems');
} }
} else if (data.id == 'find') { } else if (data.id == 'find') {
pandora.$ui.findSelect.options({value: value}); pandora.$ui.findSelect.value(value);
} else if (data.id == 'itemview') { } else if (data.id == 'itemview') {
pandora.UI.set({itemView: value}); pandora.UI.set({itemView: value});
} else if (Ox.startsWith(data.id, 'orderfilter')) { } else if (Ox.startsWith(data.id, 'orderfilter')) {

View file

@ -97,7 +97,7 @@ pandora.ui.preferencesDialog = function() {
this.options({ this.options({
title: this.options('title') == 'Subscribed' ? 'Unsubscribed' : 'Subscribed' title: this.options('title') == 'Subscribed' ? 'Unsubscribed' : 'Subscribed'
}); });
pandora.user.newsletter = data.checked; pandora.user.newsletter = data.value;
pandora.api.editPreferences({ pandora.api.editPreferences({
newsletter: pandora.user.newsletter newsletter: pandora.user.newsletter
}); });

View file

@ -15,7 +15,7 @@ pandora.ui.sectionButtons = function() {
}) })
.bindEvent({ .bindEvent({
change: function(data) { change: function(data) {
var section = data.selected[0]; var section = data.value;
if (section == 'items') { if (section == 'items') {
pandora.URL.set(pandora.Query.toString()); pandora.URL.set(pandora.Query.toString());
} else if (section == 'clips') { } else if (section == 'clips') {

View file

@ -28,29 +28,29 @@ pandora.ui.sortSelect = function(isNavigationView) {
})); }));
} }
that = Ox.Select({ that = Ox.Select({
id: 'sortSelect', id: 'sortSelect',
items: items, items: items,
width: isNavigationView ? 128 : 144 width: isNavigationView ? 128 : 144
}) })
.css({ .css({
float: isNavigationView ? 'right' : 'left', float: isNavigationView ? 'right' : 'left',
margin: isNavigationView ? '4px 4px 0 0' : '4px 0 0 4px' margin: isNavigationView ? '4px 4px 0 0' : '4px 0 0 4px'
}) })
.bindEvent({ .bindEvent({
change: function(data) { change: function(data) {
var key = data.selected[0].id; var key = data.value;
pandora.UI.set(sortKey, [{ pandora.UI.set(sortKey, [{
key: key, key: key,
operator: pandora.getSortOperator(key) operator: pandora.getSortOperator(key)
}]); }]);
}, },
pandora_listsort: function(data) { pandora_listsort: function(data) {
that.selectItem(data.value[0].key); that.selectItem(data.value[0].key);
}, },
pandora_itemsort: function(data) { pandora_itemsort: function(data) {
that.selectItem(data.value[0].key); that.selectItem(data.value[0].key);
} }
}); });
return that; return that;
}; };

View file

@ -31,7 +31,7 @@ pandora.ui.usersDialog = function() {
change: function(data) { change: function(data) {
$findInput.value() && updateList(); $findInput.value() && updateList();
$findInput.options({ $findInput.options({
placeholder: data.selected[0].title placeholder: data.title
}); });
} }
}), }),
@ -537,11 +537,11 @@ pandora.ui.usersDialog = function() {
change: function(event) { change: function(event) {
var data = {id: user.id}, key, value; var data = {id: user.id}, key, value;
if (event.id == 'status') { if (event.id == 'status') {
data.disabled = !event.data.checked; data.disabled = !event.data.value;
} else if (event.id == 'level') { } else if (event.id == 'level') {
data.level = event.data.selected[0].id; data.level = event.data.value;
} else if (event.id == 'newsletter') { } else if (event.id == 'newsletter') {
data.newsletter = event.data.checked; data.newsletter = event.data.value;
} else { } else {
data[event.id] = event.data.value; data[event.id] = event.data.value;
} }
@ -622,12 +622,12 @@ pandora.ui.usersDialog = function() {
click: function(data) { click: function(data) {
var $input = getFormItemById('message'), var $input = getFormItemById('message'),
textarea = $input.find('textarea')[0], textarea = $input.find('textarea')[0],
value = $input.options('value'); value = $input.value();
$input.options({ $input.value(
value: value.substr(0, textarea.selectionStart) value.substr(0, textarea.selectionStart)
+ '{' + data.id + '}' + '{' + data.id + '}'
+ value.substr(textarea.selectionEnd) + value.substr(textarea.selectionEnd)
}) )
.focusInput(textarea.selectionStart + data.id.length + 2); .focusInput(textarea.selectionStart + data.id.length + 2);
} }
}), }),
@ -654,7 +654,7 @@ pandora.ui.usersDialog = function() {
function selectForm(data) { function selectForm(data) {
var selected; var selected;
if (data.selected[0] == 'edit') { if (data.value == 'edit') {
$mailForm.detach(); $mailForm.detach();
selected = $list.options('selected'); selected = $list.options('selected');
if (selected.length == 1 && selected[0].level != 'guest') { if (selected.length == 1 && selected[0].level != 'guest') {
@ -690,8 +690,8 @@ pandora.ui.usersDialog = function() {
function sendMail() { function sendMail() {
pandora.api.mail({ pandora.api.mail({
to: getTo(), to: getTo(),
subject: getFormItemById('subject').options('value'), subject: getFormItemById('subject').value(),
message: getFormItemById('message').options('value'), message: getFormItemById('message').value(),
receipt: getFormItemById('receipt').value() receipt: getFormItemById('receipt').value()
}, function(result) { }, function(result) {
var title = result.status.code == 200 var title = result.status.code == 200
@ -734,7 +734,7 @@ pandora.ui.usersDialog = function() {
} }
function setHeight(data) { function setHeight(data) {
var form = $formButton.options('value'), var form = $formButton.value(),
$item = getFormItemById(form == 'edit' ? 'notes' : 'message'); $item = getFormItemById(form == 'edit' ? 'notes' : 'message');
Ox.print('$ITEM', $item) Ox.print('$ITEM', $item)
dialogHeight = data.height; dialogHeight = data.height;
@ -759,9 +759,9 @@ pandora.ui.usersDialog = function() {
function setSend() { function setSend() {
getFormItemById('send').options({ getFormItemById('send').options({
disabled: getFormItemById('to').options('value') == 'No recipients' disabled: getFormItemById('to').value() == 'No recipients'
|| getFormItemById('subject').options('value') === '' || getFormItemById('subject').value() === ''
|| getFormItemById('message').options('value') === '' || getFormItemById('message').value() === ''
}); });
} }

View file

@ -7,34 +7,34 @@ pandora.ui.viewSelect = function() {
sortKey = !ui.item ? 'listSort' : 'itemSort', sortKey = !ui.item ? 'listSort' : 'itemSort',
viewKey = !ui.item ? 'listView' : 'itemView', viewKey = !ui.item ? 'listView' : 'itemView',
that = Ox.Select({ that = Ox.Select({
id: 'viewSelect', id: 'viewSelect',
items: Ox.map(pandora.site[viewKey + 's'], function(view) { items: Ox.map(pandora.site[viewKey + 's'], function(view) {
return viewKey == 'listView' return viewKey == 'listView'
|| ['data', 'files'].indexOf(view.id) == -1 || ['data', 'files'].indexOf(view.id) == -1
|| pandora.site.capabilities.canSeeExtraItemViews[pandora.user.level] || pandora.site.capabilities.canSeeExtraItemViews[pandora.user.level]
? Ox.extend(Ox.clone(view), { ? Ox.extend(Ox.clone(view), {
checked: view.id == ui[viewKey], checked: view.id == ui[viewKey],
title: 'View ' + view.title title: 'View ' + view.title
}) })
: null; : null;
}), }),
width: !ui.item ? 144 : 128 width: !ui.item ? 144 : 128
}) })
.css({ .css({
float: 'left', float: 'left',
margin: '4px 0 0 4px' margin: '4px 0 0 4px'
}) })
.bindEvent({ .bindEvent({
change: function(data) { change: function(data) {
pandora.UI.set(viewKey, data.selected[0].id); pandora.UI.set(viewKey, data.value);
}, },
pandora_listview: function(data) { pandora_listview: function(data) {
that.selectItem(data.value); that.selectItem(data.value);
}, },
pandora_itemview: function(data) { pandora_itemview: function(data) {
that.selectItem(data.value); that.selectItem(data.value);
} }
}); });
return that; return that;
}; };