Skip to content
Snippets Groups Projects
Commit e68e5cc8 authored by Robin Appelman's avatar Robin Appelman
Browse files

Split editable select code used for quota selection into a jquery plugin

parent 4a130d10
No related branches found
No related tags found
No related merge requests found
(function ($) {
$.fn.singleSelect = function () {
return this.each(function (i, select) {
var input = $('<input/>');
select = $(select);
input.css('position', 'absolute');
input.css(select.offset());
input.css({
'box-sizing': 'border-box',
'-moz-box-sizing': 'border-box',
'margin': 0,
'width': (select.width() - 5) + 'px',
'height': (select.outerHeight() - 2) + 'px',
'border': 'none',
'box-shadow': 'none',
'margin-top': '1px',
'margin-left': '1px',
'z-index': 1000
});
input.hide();
$('body').append(input);
select.on('change', function (event) {
var value = $(this).val(),
newAttr = $('option:selected', $(this)).attr('data-new');
if (!(typeof newAttr !== 'undefined' && newAttr !== false)) {
input.hide();
select.data('previous', value);
} else {
event.stopImmediatePropagation();
input.show();
select.css('background-color', 'white');
input.focus();
}
});
$(select).data('previous', $(select).val());
input.on('change', function () {
var value = $(this).val();
if (value) {
select.children().attr('selected', null);
var existingOption = select.children().filter(function (i, option) {
return ($(option).val() == value);
});
if (existingOption.length) {
existingOption.attr('selected', 'selected');
} else {
var option = $('<option/>');
option.attr('selected', 'selected').attr('value', value).text(value);
select.children().last().before(option);
}
select.val(value);
select.css('background-color', null);
input.val(null);
input.hide();
select.change();
} else {
var previous = select.data('previous');
select.children().attr('selected', null);
select.children().each(function (i, option) {
if ($(option).val() == previous) {
$(option).attr('selected', 'selected');
}
});
select.removeClass('active');
input.hide();
}
});
input.on('blur', function () {
$(this).change();
});
});
}
})(jQuery);
......@@ -39,7 +39,6 @@ div.quota { float:right; display:block; position:absolute; right:25em; top:0; }
div.quota-select-wrapper { position: relative; }
select.quota { position:absolute; left:0; top:0.5em; width:10em; }
select.quota-user { position:relative; left:0; top:0; width:10em; }
input.quota-other { display:none; position:absolute; left:0.1em; top:0.1em; width:7em; border:none; box-shadow:none; }
div.quota>span { position:absolute; right:0; white-space:nowrap; top:.7em; color:#888; text-shadow:0 1px 0 #fff; }
select.quota.active { background: #fff; }
......
This diff is collapsed.
......@@ -33,7 +33,6 @@ $_['subadmingroups'] = array_flip($items);
</form>
<div class="quota">
<span><?php echo $l->t('Default Storage');?></span>
<div class="quota-select-wrapper">
<?php if((bool) $_['isadmin']): ?>
<select class='quota'>
<option
......@@ -60,7 +59,7 @@ $_['subadmingroups'] = array_flip($items);
<?php echo $l->t('Other');?>
...
</option>
</select> <input class='quota-other'/>
</select>
<?php endif; ?>
<?php if((bool) !$_['isadmin']): ?>
<select class='quota' disabled="disabled">
......@@ -69,7 +68,6 @@ $_['subadmingroups'] = array_flip($items);
</option>
</select>
<?php endif; ?>
</div>
</div>
</div>
......@@ -129,36 +127,34 @@ $_['subadmingroups'] = array_flip($items);
</td>
<?php endif;?>
<td class="quota">
<div class="quota-select-wrapper">
<select class='quota-user'>
<option
<?php if($user['quota']=='default') echo 'selected="selected"';?>
value='default'>
<?php echo $l->t('Default');?>
</option>
<option
<?php if($user['quota']=='none') echo 'selected="selected"';?>
value='none'>
<?php echo $l->t('Unlimited');?>
</option>
<?php foreach($_['quota_preset'] as $preset):?>
<option
<?php if($user['quota']==$preset) echo 'selected="selected"';?>
value='<?php echo $preset;?>'>
<?php echo $preset;?>
</option>
<?php endforeach;?>
<?php if($user['isQuotaUserDefined']):?>
<option selected="selected" value='<?php echo $user['quota'];?>'>
<?php echo $user['quota'];?>
</option>
<?php endif;?>
<option value='other'>
<?php echo $l->t('Other');?>
...
</option>
</select> <input class='quota-other'/>
</div>
<select class='quota-user'>
<option
<?php if($user['quota']=='default') echo 'selected="selected"';?>
value='default'>
<?php echo $l->t('Default');?>
</option>
<option
<?php if($user['quota']=='none') echo 'selected="selected"';?>
value='none'>
<?php echo $l->t('Unlimited');?>
</option>
<?php foreach($_['quota_preset'] as $preset):?>
<option
<?php if($user['quota']==$preset) echo 'selected="selected"';?>
value='<?php echo $preset;?>'>
<?php echo $preset;?>
</option>
<?php endforeach;?>
<?php if($user['isQuotaUserDefined']):?>
<option selected="selected" value='<?php echo $user['quota'];?>'>
<?php echo $user['quota'];?>
</option>
<?php endif;?>
<option value='other' data-new>
<?php echo $l->t('Other');?>
...
</option>
</select>
</td>
<td class="remove">
<?php if($user['name']!=OC_User::getUser()):?>
......
......@@ -11,6 +11,7 @@ OC_App::loadApps();
// We have some javascript foo!
OC_Util::addScript( 'settings', 'users' );
OC_Util::addScript( 'core', 'multiselect' );
OC_Util::addScript( 'core', 'singleselect' );
OC_Util::addScript('core', 'jquery.inview');
OC_Util::addStyle( 'settings', 'settings' );
OC_App::setActiveNavigationEntry( 'core_users' );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment