diff options
-rw-r--r-- | admin/ajax/togglegroups.php | 4 | ||||
-rw-r--r-- | admin/apps.php | 13 | ||||
-rw-r--r-- | admin/css/users.css | 11 | ||||
-rw-r--r-- | admin/js/users.js | 110 | ||||
-rw-r--r-- | admin/templates/users.php | 54 | ||||
-rw-r--r-- | admin/users.php | 7 | ||||
-rw-r--r-- | core/css/multiselect.css | 6 | ||||
-rw-r--r-- | core/css/styles.css | 6 | ||||
-rw-r--r-- | core/js/js.js | 24 | ||||
-rw-r--r-- | core/js/multiselect.js | 160 | ||||
-rw-r--r-- | lib/base.php | 2 | ||||
-rw-r--r-- | lib/group.php | 13 |
12 files changed, 294 insertions, 116 deletions
diff --git a/admin/ajax/togglegroups.php b/admin/ajax/togglegroups.php index 808e57dc9d6..1a0dc22be8e 100644 --- a/admin/ajax/togglegroups.php +++ b/admin/ajax/togglegroups.php @@ -19,6 +19,10 @@ $action = "add"; $username = $_POST["username"]; $group = $_POST["group"]; +if(!OC_Group::groupExists($group)){ + OC_Group::createGroup($group); +} + // Toggle group if( OC_Group::inGroup( $username, $group )){ $action = "remove"; diff --git a/admin/apps.php b/admin/apps.php index 83a48b65245..07e93728a39 100644 --- a/admin/apps.php +++ b/admin/apps.php @@ -33,11 +33,16 @@ OC_Util::addScript( "admin", "apps" ); $registeredApps=OC_App::getAllApps(); $apps=array(); + +$blacklist=array('files_imageviewer','files_textviewer');//we dont want to show configuration for these + foreach($registeredApps as $app){ - $info=OC_App::getAppInfo($app); - $active=(OC_Appconfig::getValue($app,'enabled','no')=='yes')?true:false; - $info['active']=$active; - $apps[]=$info; + if(array_search($app,$blacklist)===false){ + $info=OC_App::getAppInfo($app); + $active=(OC_Appconfig::getValue($app,'enabled','no')=='yes')?true:false; + $info['active']=$active; + $apps[]=$info; + } } $categories=OC_OCSClient::getCategories(); diff --git a/admin/css/users.css b/admin/css/users.css index 521217df4f4..27bd704c599 100644 --- a/admin/css/users.css +++ b/admin/css/users.css @@ -1,5 +1,6 @@ -form {display:inline} -td.remove>img,td.select>input{display:none;cursor:pointer} -td.select,td.remove{width:1em} -tr:hover>td.remove>img{display:inline} -li.selected{background-color:#ddd} +form { display:inline } +td.remove>img,td.select>input { display:none;cursor:pointer } +td.select,td.remove { width:1em } +tr:hover>td.remove>img { display:inline } +li.selected { background-color:#ddd } +#content>table { margin-top:6.5em } diff --git a/admin/js/users.js b/admin/js/users.js index 7e643fb60a2..7402255750f 100644 --- a/admin/js/users.js +++ b/admin/js/users.js @@ -1,5 +1,37 @@ $(document).ready(function(){ - $('select[multiple]').chosen(); + function applyMultiplySelect(element){ + var checked=[]; + var user=element.data('username') + if(element.data('userGroups')){ + checked=element.data('userGroups').split(', '); + } + if(user){ + var checkHandeler=function(group){ + if(user==OC.currentUser && group=='admin'){ + return false; + } + $.post( + OC.filePath('admin','ajax','togglegroups.php'), + { + username:user, + group:group + }, + function(){} + ); + } + }else{ + checkHandeler=false; + } + element.multiSelect({ + createText:'add group', + checked:checked, + oncheck:checkHandeler, + onuncheck:checkHandeler + }); + } + $('select[multiple]').each(function(index,element){ + applyMultiplySelect($(element)); + }); $('td.remove>img').live('click',function(event){ var uid=$(this).parent().parent().data('uid'); @@ -17,7 +49,7 @@ $(document).ready(function(){ event.preventDefault(); var username=$('#newusername').val(); var password=$('#newuserpassword').val(); - var groups=$('#newusergroups').val(); + var groups=$('#newusergroups').prev().children('div').data('settings').checked; $.post( OC.filePath('admin','ajax','createuser.php'), { @@ -29,72 +61,18 @@ $(document).ready(function(){ } ); - var tr=$('#rightcontent tr').first().clone(); + var tr=$('#content table tr').first().clone(); tr.attr('data-uid',username); tr.find('td.name').text(username); - tr.find('td.groups').text(groups.join(', ')); - $('#rightcontent tr').first().after(tr); - if(groups.indexOf($('#leftcontent li.selected').text().trim())!=-1){ - tr.find('td.select input').attr('checked','checked'); - } - }); - - $('#newgroup').submit(function(event){ - event.preventDefault(); - var name=$('#newgroupname').val(); - $.post( - OC.filePath('admin','ajax','creategroup.php'), - {groupname:name}, - function(result){ - - } - ); - $('#newusergroups').append('<option value="'+name+'">'+name+'</option>'); - $('select[multiple]').trigger("liszt:updated"); - var li=$('#leftcontent li').first().next().clone(); - li.text(name); - $('#leftcontent li').first().after(li); - }); - - $('#leftcontent li').live('click',function(event){ - $('#leftcontent li').removeClass('selected'); - $(this).addClass('selected'); - $('#rightcontent tr td.select input').show(); - $('#rightcontent tr td.select input').removeAttr('checked'); - var group=$(this).text().trim(); - var rows=$('#rightcontent tr').filter(function(i,tr){ - return ($(tr).children('td.groups').text().split(', ').indexOf(group)>-1); + var select=$('<select multiple="multiple" data-placehoder="Groups" title="Groups">'); + select.data('username',username); + select.data('userGroups',groups.join(', ')); + tr.find('td.groups').empty(); + $.each($('#content table').data('groups').split(', '),function(i,group){ + select.append($('<option value="'+group+'">'+group+'</option>')); }); - rows.find('td.select input').attr('checked','checked'); - }); - $('#rightcontent tr td.select input').live('change',function(event){ - var group=$('#leftcontent li.selected').text().trim(); - var user=$(this).parent().parent().children('td.name').text().trim(); - if(group=='admin' && user==OC.currentUser){ - event.preventDefault(); - $(this).attr('checked','checked'); - return false; - } - if(group){ - $.post( - OC.filePath('admin','ajax','togglegroups.php'), - { - username:user, - group:group - }, - function(result){ - - } - ); - var groups=$(this).parent().parent().children('td.groups').text().trim().split(', '); - if(groups[0]=='') groups.pop(); - var index=groups.indexOf(group); - if(index==-1){ - groups.push(group); - }else{ - groups.splice(index,1); - } - $(this).parent().parent().children('td.groups').text(groups.join(', ')); - } + tr.find('td.groups').append(select); + applyMultiplySelect(select); + $('#content table tr').last().after(tr); }); }); diff --git a/admin/templates/users.php b/admin/templates/users.php index 00daf4c5263..63f512d4432 100644 --- a/admin/templates/users.php +++ b/admin/templates/users.php @@ -1,8 +1,4 @@ <div id="controls"> - <form id="newgroup"> - <input id="newgroupname" placeholder="<?php echo $l->t('Name')?>"></input> - <input type="submit" value="<?php echo $l->t('Create')?>"></input> - </form> <form id="newuser"> <input id="newusername" placeholder="<?php echo $l->t('Name')?>"></input> <input type="password" id="newuserpassword" placeholder="<?php echo $l->t('Password')?>"></input> @@ -14,29 +10,29 @@ <input type="submit" value="<?php echo $l->t('Create')?>"></input> </form> </div> -<ul id="leftcontent"> - <?php foreach($_["groups"] as $group): ?> - <li data-gid="<?php echo $group["name"]; ?>"> - <?php echo $group["name"] ?> - </li> +<?php +$allGroups=array(); +foreach($_["groups"] as $group){ + $allGroups[]=$group['name']; +} +?> +<table data-groups="<?php echo implode(', ',$allGroups);?>"> + <?php foreach($_["users"] as $user): ?> + <tr data-uid="<?php echo $user["name"] ?>"> + <td class="select"><input type="checkbox"></input></td> + <td class="name"><?php echo $user["name"]; ?></td> + <td class="groups"> + <select data-username="<?php echo $user['name'] ;?>" data-user-groups="<?php echo $user['groups'] ;?>" data-placeholder="groups" title="<?php echo $l->t('Groups')?>" multiple="multiple"> + <?php foreach($_["groups"] as $group): ?> + <option value="<?php echo $group['name'];?>"><?php echo $group['name'];?></option> + <?php endforeach;?> + </select> + </td> + <td class="remove"> + <?php if($user['name']!=OC_User::getUser()):?> + <img alt="Remove" title="<?php echo $l->t('Remove')?>" class='svg' src='<?php echo image_path('core','actions/delete.svg') ?>'/> + <?php endif;?> + </td> + </tr> <?php endforeach; ?> -</ul> -<div id="rightcontent"> - <table> - <?php foreach($_["users"] as $user): ?> - <tr data-uid="<?php echo $user["name"] ?>"> - <td class="select"><input type="checkbox"></input></td> - <td class="name"><?php echo $user["name"]; ?></td> - <td class="groups"><?php if( $user["groups"] ){ echo $user["groups"]; }else{echo " ";} ?></td> - <td class="remove"> - <?php if($user['name']!=OC_User::getUser()):?> - <img alt="Remove" title="<?php echo $l->t('Remove')?>" class='svg' src='<?php echo image_path('core','actions/delete.svg') ?>'/> - <?php endif;?> - </td> - </tr> - <?php endforeach; ?> - </table> -</div> -<div id="#selecteduser"> - -</div> +</table> diff --git a/admin/users.php b/admin/users.php index 4a83510cb72..b120e10d437 100644 --- a/admin/users.php +++ b/admin/users.php @@ -38,12 +38,7 @@ $users = array(); $groups = array(); foreach( OC_User::getUsers() as $i ){ - // Do some more work here soon - $ingroups = array(); - foreach( OC_Group::getUserGroups( $i ) as $userGroup ){ - $ingroups[] = $userGroup; - } - $users[] = array( "name" => $i, "groups" => join( ", ", $ingroups )); + $users[] = array( "name" => $i, "groups" => join( ", ", OC_Group::getUserGroups( $i ) )); } foreach( OC_Group::getGroups() as $i ){ diff --git a/core/css/multiselect.css b/core/css/multiselect.css new file mode 100644 index 00000000000..d78dede95c0 --- /dev/null +++ b/core/css/multiselect.css @@ -0,0 +1,6 @@ +ul.multiselectoptions { z-index:49; position:absolute; background-color:#fff; padding-top:.5em; border-bottom-left-radius:.5em; border-bottom-right-radius:.5em; border:1px solid #ddd; border-top:none; } +div.multiselect { padding-right:.6em; display:inline; position:relative; display:inline-block } +div.multiselect.active { background-color:#fff; border-bottom:none; border-bottom-left-radius:0; border-bottom-right-radius:0; z-index:50; position:relative } +div.multiselect>span:first-child { margin-right:2em; } +div.multiselect>span:last-child { float:right; position:relative } +ul.multiselectoptions input.new{ margin:0; padding-bottom:0.2em; padding-top:0.2em; border-top-left-radius:0; border-top-right-radius:0; } diff --git a/core/css/styles.css b/core/css/styles.css index 273d7443a8b..1703dc152f2 100644 --- a/core/css/styles.css +++ b/core/css/styles.css @@ -33,12 +33,12 @@ h1 { margin:1em 3em 1em 0; border-bottom:1px solid #666; text-transform:uppercas /* INPUTS */ input[type="text"], input[type="password"] { cursor:text; } -input, select { font-size:1em; width:10em; margin:.3em; padding:.6em .5em .4em; background:#fff; color:#333; border:1px solid #ddd; -moz-box-shadow:0 1px 1px #fff, 0 2px 0 #bbb inset; -webkit-box-shadow:0 1px 1px #fff, 0 1px 0 #bbb inset; box-shadow:0 1px 1px #fff, 0 1px 0 #bbb inset; -moz-border-radius:.5em; -webkit-border-radius:.5em; border-radius:.5em; } +input, select, .button { font-size:1em; width:10em; margin:.3em; padding:.6em .5em .4em; background:#fff; color:#333; border:1px solid #ddd; -moz-box-shadow:0 1px 1px #fff, 0 2px 0 #bbb inset; -webkit-box-shadow:0 1px 1px #fff, 0 1px 0 #bbb inset; box-shadow:0 1px 1px #fff, 0 1px 0 #bbb inset; -moz-border-radius:.5em; -webkit-border-radius:.5em; border-radius:.5em; } input[type="text"], input[type="password"] { background:#f8f8f8; color:#555; cursor:text; } input[type="text"]:hover, input[type="text"]:focus, input[type="password"]:hover, input[type="password"]:focus { background:#fff; color:#333; } -input[type="submit"], input[type="button"] { width:auto; padding:.4em; border:1px solid #ddd; font-weight:bold; cursor:pointer; background:#f8f8f8; color:#555; text-shadow:#fff 0 1px 0; -moz-box-shadow:0 1px 1px #fff, 0 1px 1px #fff inset; -webkit-box-shadow:0 1px 1px #fff, 0 1px 1px #fff inset; -moz-border-radius:.5em; -webkit-border-radius:.5em; border-radius:.5em; } -input[type="submit"]:hover, input[type="submit"]:focus, input[type="button"]:hover, input[type="button"]:focus { background:#fff; color:#333; } +input[type="submit"], input[type="button"], .button { width:auto; padding:.4em; border:1px solid #ddd; font-weight:bold; cursor:pointer; background:#f8f8f8; color:#555; text-shadow:#fff 0 1px 0; -moz-box-shadow:0 1px 1px #fff, 0 1px 1px #fff inset; -webkit-box-shadow:0 1px 1px #fff, 0 1px 1px #fff inset; -moz-border-radius:.5em; -webkit-border-radius:.5em; border-radius:.5em; } +input[type="submit"]:hover, input[type="submit"]:focus, input[type="button"]:hover, input[type="button"]:focus, .button:hover { background:#fff; color:#333; } input[type="checkbox"] { width:auto; } #body-login input { font-size:1.5em; } diff --git a/core/js/js.js b/core/js/js.js index f4756d97b25..dc8345545a6 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -275,7 +275,29 @@ $(document).ready(function(){ }) }); - +if (!Array.prototype.map){ + Array.prototype.map = function(fun /*, thisp */){ + "use strict"; + + if (this === void 0 || this === null) + throw new TypeError(); + + var t = Object(this); + var len = t.length >>> 0; + if (typeof fun !== "function") + throw new TypeError(); + + var res = new Array(len); + var thisp = arguments[1]; + for (var i = 0; i < len; i++){ + if (i in t){ + res[i] = fun.call(thisp, t[i], i, t); + } + } + + return res; + }; +} /* diff --git a/core/js/multiselect.js b/core/js/multiselect.js new file mode 100644 index 00000000000..559cdf9b167 --- /dev/null +++ b/core/js/multiselect.js @@ -0,0 +1,160 @@ +(function( $ ){ + var multiSelectId=-1; + $.fn.multiSelect=function(options){ + multiSelectId++; + var settings = { + 'createCallback':false, + 'createText':false, + 'title':this.attr('title'), + 'checked':[], + 'oncheck':false, + 'onuncheck':false, + }; + $.extend(settings,options); + var button=$('<div class="multiselect button"><span>'+settings.title+'</span><span>▾</span></div>'); + if(settings.checked.length>0){ + button.children('span').first().text(settings.checked.join(', ')); + } + var span=$('<span/>'); + span.append(button); + button.data('id',multiSelectId); + button.selectedItems=[]; + this.hide(); + this.before(span); + settings.minWidth=button.width(); + button.css('min-width',settings.minWidth); + settings.minOuterWidth=button.outerWidth()-2; + button.data('settings',settings); + + button.click(function(event){ + var button=$(this); + if(button.parent().children('ul').length>0){ + button.parent().children('ul').slideUp(400,function(){ + button.parent().children('ul').remove(); + button.removeClass('active'); + }); + return; + } + var lists=$('ul.multiselectoptions'); + lists.slideUp(400,function(){ + lists.remove(); + $('div.multiselect').removeClass('active'); + button.addClass('active'); + }); + button.addClass('active'); + event.stopPropagation(); + var options=$(this).parent().next().children().map(function(){return $(this).val()}); + var list=$('<ul class="multiselectoptions"/>').hide().appendTo($(this).parent()); + function createItem(item,checked){ + var id='ms'+multiSelectId+'-option-'+item; + var input=$('<input id="'+id+'" type="checkbox"/>'); + var label=$('<label for="'+id+'">'+item+'</label>'); + if(settings.checked.indexOf(item)!=-1 || checked){ + input.attr('checked','checked'); + } + if(checked){ + settings.checked.push(item); + } + input.change(function(){ + var groupname=$(this).next().text(); + if($(this).attr('checked')){ + settings.checked.push(groupname); + if(settings.oncheck){ + if(settings.oncheck(groupname)===false){ + $(this).removeAttr('checked'); + return; + } + } + }else{ + var index=settings.checked.indexOf(groupname); + settings.checked.splice(index,1); + if(settings.onuncheck){ + if(settings.onuncheck(groupname)===false){ + $(this).attr('checked','checked'); + return; + } + } + } + var oldWidth=button.width(); + if(settings.checked.length>0){ + button.children('span').first().text(settings.checked.join(', ')); + }else{ + button.children('span').first().text(settings.title); + } + var newOuterWidth=Math.max((button.outerWidth()-2),settings.minOuterWidth)+'px' + var newWidth=Math.max(button.width(),settings.minWidth); + button.css('height',button.height()); + button.css('white-space','nowrap'); + button.css('width',oldWidth); + button.animate({'width':newWidth},undefined,undefined,function(){ + button.css('width',''); + }); + list.animate({'width':newOuterWidth}); + }); + var li=$('<li></li>'); + li.append(input).append(label); + return li; + } + $.each(options,function(index,item){ + list.append(createItem(item)); + }); + button.parent().data('preventHide',false); + if(settings.createText){ + var li=$('<li>+ <em>'+settings.createText+'<em></li>'); + li.click(function(event){ + li.empty(); + var input=$('<input class="new">'); + li.append(input); + input.focus(); + input.css('width',button.width()); + button.parent().data('preventHide',true); + input.keypress(function(event) { + if(event.keyCode == 13) { + event.preventDefault(); + event.stopPropagation(); + var li=$(this).parent(); + $(this).remove(); + li.text('+ '+settings.createText); + li.before(createItem($(this).val())); + li.prev().children('input').trigger('click'); + button.parent().data('preventHide',false); + var select=button.parent().next(); + select.append($('<option value="'+$(this).val()+'">'+$(this).val()+'</option>')); + if(settings.createCallback){ + settings.createCallback(); + } + } + }); + input.blur(function(){ + event.preventDefault(); + event.stopPropagation(); + $(this).remove(); + li.text('+ '+settings.createText); + setTimeout(function(){ + button.parent().data('preventHide',false); + },100); + }); + }); + list.append(li); + } + var pos=button.position(); + list.css('top',pos.top+button.outerHeight()-5); + list.css('left',pos.left+3); + list.css('width',(button.outerWidth()-2)+'px'); + list.slideDown(); + list.click(function(event){ + event.stopPropagation(); + }); + }); + $(window).click(function(){ + if(!button.parent().data('preventHide')){ + button.parent().children('ul').slideUp(400,function(){ + button.parent().children('ul').remove(); + button.removeClass('active'); + }); + } + }); + + return span; + }; +})( jQuery );
\ No newline at end of file diff --git a/lib/base.php b/lib/base.php index 93b8e0b584d..2e735514347 100644 --- a/lib/base.php +++ b/lib/base.php @@ -149,9 +149,11 @@ OC_Group::setBackend( OC_Config::getValue( "groupbackend", "database" )); OC_Util::addScript( "jquery-1.6.2.min" ); OC_Util::addScript( "jquery-ui-1.8.14.custom.min" ); OC_Util::addScript( "js" ); +OC_Util::addScript( "multiselect" ); OC_Util::addScript('search','result'); OC_Util::addStyle( "jquery-ui-1.8.14.custom" ); OC_Util::addStyle( "styles" ); +OC_Util::addStyle( "multiselect" ); // Load Apps // This includes plugins for users and filesystems as well diff --git a/lib/group.php b/lib/group.php index 1161b9035fa..54dc0b6463c 100644 --- a/lib/group.php +++ b/lib/group.php @@ -171,11 +171,11 @@ class OC_Group { */ public static function addToGroup( $uid, $gid ){ // Does the user exist? - if( !in_array( $uid, OC_User::getUsers())){ + if( !OC_User::userExists($uid)){ return false; } // Does the group exist? - if( !in_array( $gid, self::getGroups())){ + if( !OC_Group::groupExists($gid)){ return false; } @@ -234,4 +234,13 @@ class OC_Group { public static function getGroups(){ return self::$_backend->getGroups(); } + + /** + * check if a group exists + * @param string $gid + * @return bool + */ + public static function groupExists($gid){ + return in_array( $gid, self::getGroups()); + } } |