List manip improvements from mdawaffe. fixes #2633

git-svn-id: http://svn.automattic.com/wordpress/trunk@3684 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2006-04-04 00:16:27 +00:00
parent d02d4a9319
commit 33ccb31e88
8 changed files with 28 additions and 24 deletions

View File

@ -2,7 +2,7 @@
require_once('../wp-config.php');
header('Content-type: text/javascript; charset=' . get_settings('blog_charset'), true);
?>
addLoadEvent(function(){catList=new listMan('categorychecklist');catList.ajaxRespEl='jaxcat';catList.clearInputs.push('newcat');catList.topAdder=1;catList.alt=0});
addLoadEvent(function(){catList=new listMan('categorychecklist');catList.ajaxRespEl='jaxcat';catList.topAdder=1;catList.alt=0;catList.showLink=0;});
addLoadEvent(newCatAddIn);
function newCatAddIn() {
if ( !document.getElementById('jaxcat') ) return false;

View File

@ -2,5 +2,4 @@ addLoadEvent(newCategoryAddIn);
function newCategoryAddIn() {
if (!theList.theList) return false;
document.forms.addcat.submit.onclick = function(e) {return killSubmit('theList.ajaxAdder("cat", "addcat");', e); };
theList.clearInputs.push('cat_name','category_parent','category_description');
}

View File

@ -147,8 +147,6 @@ cat_rows();
</tbody>
</table>
<div id="ajax-response"></div>
</div>
<?php if ( current_user_can('manage_categories') ) : ?>
@ -159,14 +157,16 @@ cat_rows();
<div class="wrap">
<h2><?php _e('Add New Category') ?></h2>
<form name="addcat" id="addcat" action="categories.php" method="post">
<p><?php _e('Name:') ?><br />
<div class="alignleft"><?php _e('Name:') ?><br />
<input type="text" name="cat_name" id="cat_name" value="" /></p>
<p><?php _e('Category parent:') ?><br />
<select name='category_parent' id='category_parent' class='postform'>
<option value='0'><?php _e('None') ?></option>
<?php wp_dropdown_cats(0); ?>
</select></p>
</select>
</div>
<div id="ajax-response" class="alignleft"></div>
<br class="clear" />
<p><?php _e('Description: (optional)') ?> <br />
<textarea name="category_description" id="category_description" rows="5" cols="50" style="width: 97%;"></textarea></p>
<p class="submit"><input type="hidden" name="action" value="addcat" /><input type="submit" name="submit" value="<?php _e('Add Category &raquo;') ?>" /></p>

View File

@ -1,5 +1,6 @@
addLoadEvent(customFieldsAddIn);
function customFieldsAddIn() {
theList.showLink=0;
if (!theList.theList) return false;
inputs = theList.theList.getElementsByTagName('input');
for ( var i=0; i < inputs.length; i++ ) {
@ -14,7 +15,6 @@ function customFieldsAddIn() {
document.getElementById('metakeyinput').onkeypress = function(e) {return killSubmit('theList.inputData+="&id="+document.getElementById("post_ID").value;theList.ajaxAdder("meta", "newmeta", customFieldsOnComplete);', e); };
document.getElementById('updatemetasub').onclick = function(e) {return killSubmit('theList.inputData+="&id="+document.getElementById("post_ID").value;theList.ajaxAdder("meta", "newmeta", customFieldsOnComplete);', e); };
theList.clearInputs.push('metakeyselect','metakeyinput','metavalue');
}
function customFieldsOnComplete() {
var pidEl = document.getElementById('post_ID');

View File

@ -40,7 +40,8 @@ function xfn_check($class, $value = '', $type = 'check') {
<h3 class="dbx-handle"><?php _e('Categories') ?></h3>
<div class="dbx-content">
<p id="jaxcat"></p>
<div id="categorychecklist"><?php dropdown_categories(get_settings('default_link_category')); ?></div></div>
<ul id="categorychecklist"><?php dropdown_categories(get_settings('default_link_category')); ?></ul>
</div>
</fieldset>
<fieldset class="dbx-box">
@ -250,4 +251,4 @@ function xfn_check($class, $value = '', $type = 'check') {
<?php endif; ?>
</div>
</form>
</div>
</div>

View File

@ -7,20 +7,20 @@ function deleteSomething(what,id,message){if(!message)message="<?php printf(__('
function dimSomething(what,id,dimClass){return theList.ajaxDimmer(what,id,dimClass);}
function WPAjax(file, responseEl){//class WPAjax extends sack
this.getResponseElement=function(r){var p=document.getElementById(r+'-p');if(!p){p=document.createElement('span');p.id=r+'ajax-response-p';document.getElementById(r).appendChild(p);}this.myResponseElement=p; }
this.getResponseElement=function(r){var p=document.getElementById(r+'-p');if(!p){p=document.createElement('span');p.id=r+'-p';document.getElementById(r).appendChild(p);}this.myResponseElement=p; }
this.parseAjaxResponse=function(){
if(isNaN(this.response)){this.myResponseElement.innerHTML='<div class="error">'+this.response+'</div>';return false;}
if(isNaN(this.response)){this.myResponseElement.innerHTML='<div class="error"><p>'+this.response+'</p></div>';return false;}
this.response=parseInt(this.response,10);
if(-1==this.response){this.myResponseElement.innerHTML="<?php _e("You don't have permission to do that."); ?>";return false;}
else if(0==this.response){this.myResponseElement.innerHTML="<?php _e("Something odd happened. Try refreshing the page? Either that or what you tried to change never existed in the first place."); ?>";return false;}
if(-1==this.response){this.myResponseElement.innerHTML="<div class='error'><p><?php _e("You don't have permission to do that."); ?></p></div>";return false;}
else if(0==this.response){this.myResponseElement.innerHTML="<div class='error'><p><?php _e("Something odd happened. Try refreshing the page? Either that or what you tried to change never existed in the first place."); ?></p></div>";return false;}
return true;
}
this.parseAjaxResponseXML=function(){
if(this.responseXML&&typeof this.responseXML=='object')return true;
if(isNaN(this.response)){this.myResponseElement.innerHTML='<div class="error">'+this.response+'</div>';return false;}
if(isNaN(this.response)){this.myResponseElement.innerHTML='<div class="error"><p>'+this.response+'</p></div>';return false;}
var r=parseInt(this.response,10);
if(-1==r){this.myResponseElement.innerHTML="<?php _e("You don't have permission to do that."); ?>";}
else if(0==r){this.myResponseElement.innerHTML="<?php _e("Invalid Entry."); ?>";}
if(-1==r){this.myResponseElement.innerHTML="<div class='error'><p><?php _e("You don't have permission to do that."); ?></p></div>";}
else if(0==r){this.myResponseElement.innerHTML="<div class='error'><p><?php _e("Invalid Entry."); ?></p></div>";}
return false;
}
this.init(file,responseEl);
@ -36,7 +36,7 @@ function WPAjax(file, responseEl){//class WPAjax extends sack
function listMan(theListId){
this.theList=null;
this.ajaxRespEl=null;
this.inputData='';this.clearInputs=new Array();
this.inputData='';this.clearInputs=new Array();this.showLink=1;
this.topAdder=0;this.alt='alternate';this.recolorPos;this.reg_color='#FFFFFF';this.alt_color='#F1F1F1';
var listType;var listItems;
self.aTrap=0;
@ -57,10 +57,12 @@ function listMan(theListId){
if(exists)tempObj.replaceListItem(exists.id,getNodeValue(newItems[c],'newitem'),newItems.length,update);
else tempObj.addListItem(getNodeValue(newItems[c],'newitem'),newItems.length);
}}
this.myResponseElement.innerHTML='';tempObj.inputData='';
tempObj.inputData='';
if(tempObj.showLink){this.myResponseElement.innerHTML='<div id="jumplink" class="updated fade"><p><a href="#'+what+'-'+id+'"><?php _e('Jump to new item'); ?></a></p></div>';}
else this.myResponseElement.innerHTML='';
for(var i=0;i<tempObj.clearInputs.length;i++){try{var theI=document.getElementById(tempObj.clearInputs[i]);if(theI.tagName.match(/select/i))theI.selectedIndex=0;else theI.value='';}catch(e){}}
if(onComplete&&typeof onComplete=='function')onComplete();
tempObj.recolorList(tempObj.recolorPos,1000)
tempObj.recolorList(tempObj.recolorPos,1000);
}
this.ajaxAdd.runAJAX('action='+(update?'update-':'add-')+what+this.inputData);
return false;
@ -123,9 +125,9 @@ function listMan(theListId){
for(var i=0;i<inputs[a].length;i++){
if('action'==inputs[a][i].name)continue;
if('text'==inputs[a][i].type||'password'==inputs[a][i].type||'hidden'==inputs[a][i].type||inputs[a][i].tagName.match(/textarea/i)){
this.inputData+='&'+inputs[a][i].name+'='+encodeURIComponent(inputs[a][i].value);
this.inputData+='&'+inputs[a][i].name+'='+encodeURIComponent(inputs[a][i].value);if('hidden'!=inputs[a][i].type)this.clearInputs.push(inputs[a][i].id);
}else if(inputs[a][i].tagName.match(/select/i)){
this.inputData+='&'+inputs[a][i].name+'='+encodeURIComponent(inputs[a][i].options[inputs[a][i].selectedIndex].value);
this.inputData+='&'+inputs[a][i].name+'='+encodeURIComponent(inputs[a][i].options[inputs[a][i].selectedIndex].value);this.clearInputs.push(inputs[a][i].id);
}
}
}

View File

@ -16,6 +16,5 @@ function addUserSubmit() {
var roleEl = document.getElementById('role');
var role = roleEl.options[roleEl.selectedIndex].value;
if ( !theUserLists['role-' + role] ) return true;
theUserLists['role-' + role].clearInputs.push('user_login', 'first_name', 'last_name', 'email', 'url', 'pass1', 'pass2', 'role');
return theUserLists['role-' + role].ajaxAdder('user', 'adduser');
}

View File

@ -627,7 +627,7 @@ table .vers, table .name {
width: 170px;
}
#templateside h3, #postcustom p {
#templateside h3, #postcustom p.submit {
margin: 0;
}
@ -968,3 +968,6 @@ input#catadd { background: #a4a4a4;
margin: 0;
padding: 0;
}
#ajax-response.alignleft {
margin-left: 2em;
}