web/wp-admin/js/inline-edit-post.dev.js
branchwordpress
changeset 132 4d4862461b8d
parent 109 03b0d1493584
equal deleted inserted replaced
131:a4642baaf829 132:4d4862461b8d
     5 	init : function() {
     5 	init : function() {
     6 		var t = this, qeRow = $('#inline-edit'), bulkRow = $('#bulk-edit');
     6 		var t = this, qeRow = $('#inline-edit'), bulkRow = $('#bulk-edit');
     7 
     7 
     8 		t.type = $('table.widefat').hasClass('page') ? 'page' : 'post';
     8 		t.type = $('table.widefat').hasClass('page') ? 'page' : 'post';
     9 		t.what = '#'+t.type+'-';
     9 		t.what = '#'+t.type+'-';
    10 
       
    11 		// get all editable rows
       
    12 		t.rows = $('tr.iedit');
       
    13 
    10 
    14 		// prepare the edit rows
    11 		// prepare the edit rows
    15 		qeRow.keyup(function(e) { if(e.which == 27) return inlineEditPost.revert(); });
    12 		qeRow.keyup(function(e) { if(e.which == 27) return inlineEditPost.revert(); });
    16 		bulkRow.keyup(function(e) { if (e.which == 27) return inlineEditPost.revert(); });
    13 		bulkRow.keyup(function(e) { if (e.which == 27) return inlineEditPost.revert(); });
    17 
    14 
    29 				pw.attr('disabled', '');
    26 				pw.attr('disabled', '');
    30 			}
    27 			}
    31 		});
    28 		});
    32 
    29 
    33 		// add events
    30 		// add events
    34 		t.addEvents(t.rows);
    31 		$('a.editinline').live('click', function() { inlineEditPost.edit(this); return false; });
    35 
    32 
    36 		$('#bulk-title-div').parents('fieldset').after(
    33 		$('#bulk-title-div').parents('fieldset').after(
    37 			$('#inline-edit fieldset.inline-edit-categories').clone()
    34 			$('#inline-edit fieldset.inline-edit-categories').clone()
    38 		).siblings( 'fieldset:last' ).prepend(
    35 		).siblings( 'fieldset:last' ).prepend(
    39 			$('#inline-edit label.inline-edit-tags').clone()
    36 			$('#inline-edit label.inline-edit-tags').clone()
    74 	toggle : function(el) {
    71 	toggle : function(el) {
    75 		var t = this;
    72 		var t = this;
    76 		$(t.what+t.getId(el)).css('display') == 'none' ? t.revert() : t.edit(el);
    73 		$(t.what+t.getId(el)).css('display') == 'none' ? t.revert() : t.edit(el);
    77 	},
    74 	},
    78 
    75 
    79 	addEvents : function(r) {
       
    80 		r.each(function() {
       
    81 			var row = $(this);
       
    82 			$('a.editinline', row).click(function() { inlineEditPost.edit(this); return false; });
       
    83 		});
       
    84 	},
       
    85 
       
    86 	setBulk : function() {
    76 	setBulk : function() {
    87 		var te = '', type = this.type, tax;
    77 		var te = '', type = this.type, tax, c = true;
    88 		this.revert();
    78 		this.revert();
    89 
    79 
    90 		$('#bulk-edit td').attr('colspan', $('.widefat:first thead th:visible').length);
    80 		$('#bulk-edit td').attr('colspan', $('.widefat:first thead th:visible').length);
    91 		$('table.widefat tbody').prepend( $('#bulk-edit') );
    81 		$('table.widefat tbody').prepend( $('#bulk-edit') );
    92 		$('#bulk-edit').addClass('inline-editor').show();
    82 		$('#bulk-edit').addClass('inline-editor').show();
    93 
    83 
    94 		$('tbody th.check-column input[type="checkbox"]').each(function(i){
    84 		$('tbody th.check-column input[type="checkbox"]').each(function(i){
    95 			if ( $(this).attr('checked') ) {
    85 			if ( $(this).attr('checked') ) {
       
    86 				c = false;
    96 				var id = $(this).val(), theTitle;
    87 				var id = $(this).val(), theTitle;
    97 				theTitle = $('#inline_'+id+' .post_title').text() || inlineEditL10n.notitle;
    88 				theTitle = $('#inline_'+id+' .post_title').text() || inlineEditL10n.notitle;
    98 				te += '<div id="ttle'+id+'"><a id="_'+id+'" class="ntdelbutton" title="'+inlineEditL10n.ntdeltitle+'">X</a>'+theTitle+'</div>';
    89 				te += '<div id="ttle'+id+'"><a id="_'+id+'" class="ntdelbutton" title="'+inlineEditL10n.ntdeltitle+'">X</a>'+theTitle+'</div>';
    99 			}
    90 			}
   100 		});
    91 		});
       
    92 
       
    93 		if ( c )
       
    94 			return this.revert();
   101 
    95 
   102 		$('#bulk-titles').html(te);
    96 		$('#bulk-titles').html(te);
   103 		$('#bulk-titles a').click(function() {
    97 		$('#bulk-titles a').click(function() {
   104 			var id = $(this).attr('id').substr(1);
    98 			var id = $(this).attr('id').substr(1);
   105 
    99 
   134 			$(editRow).addClass('alternate');
   128 			$(editRow).addClass('alternate');
   135 		$(t.what+id).hide().after(editRow);
   129 		$(t.what+id).hide().after(editRow);
   136 
   130 
   137 		// populate the data
   131 		// populate the data
   138 		rowData = $('#inline_'+id);
   132 		rowData = $('#inline_'+id);
       
   133 		if ( !$(':input[name="post_author"] option[value=' + $('.post_author', rowData).text() + ']', editRow).val() ) {
       
   134 			// author no longer has edit caps, so we need to add them to the list of authors
       
   135 			$(':input[name="post_author"]', editRow).prepend('<option value="' + $('.post_author', rowData).text() + '">' + $('#' + t.type + '-' + id + ' .author').text() + '</option>');
       
   136 		}
       
   137 
   139 		for ( f = 0; f < fields.length; f++ ) {
   138 		for ( f = 0; f < fields.length; f++ ) {
   140 			$(':input[name="'+fields[f]+'"]', editRow).val( $('.'+fields[f], rowData).text() );
   139 			$(':input[name="'+fields[f]+'"]', editRow).val( $('.'+fields[f], rowData).text() );
   141 		}
   140 		}
   142 
   141 
   143 		if ( $('.comment_status', rowData).text() == 'open' )
   142 		if ( $('.comment_status', rowData).text() == 'open' )
   189 
   188 
   190 		return false;
   189 		return false;
   191 	},
   190 	},
   192 
   191 
   193 	save : function(id) {
   192 	save : function(id) {
   194 		var params, fields;
   193 		var params, fields, page = $('.post_status_page').val() || '';
   195 
   194 
   196 		if( typeof(id) == 'object' )
   195 		if( typeof(id) == 'object' )
   197 			id = this.getId(id);
   196 			id = this.getId(id);
   198 
   197 
   199 		$('table.widefat .inline-edit-save .waiting').show();
   198 		$('table.widefat .inline-edit-save .waiting').show();
   200 
   199 
   201 		params = {
   200 		params = {
   202 			action: 'inline-save',
   201 			action: 'inline-save',
   203 			post_type: this.type,
   202 			post_type: this.type,
   204 			post_ID: id,
   203 			post_ID: id,
   205 			edit_date: 'true'
   204 			edit_date: 'true',
       
   205 			post_status: page
   206 		};
   206 		};
   207 
   207 
   208 		fields = $('#edit-'+id+' :input').fieldSerialize();
   208 		fields = $('#edit-'+id+' :input').serialize();
   209 		params = fields + '&' + $.param(params);
   209 		params = fields + '&' + $.param(params);
   210 
   210 
   211 		// make ajax request
   211 		// make ajax request
   212 		$.post('admin-ajax.php', params,
   212 		$.post('admin-ajax.php', params,
   213 			function(r) {
   213 			function(r) {
   215 
   215 
   216 				if (r) {
   216 				if (r) {
   217 					if ( -1 != r.indexOf('<tr') ) {
   217 					if ( -1 != r.indexOf('<tr') ) {
   218 						$(inlineEditPost.what+id).remove();
   218 						$(inlineEditPost.what+id).remove();
   219 						$('#edit-'+id).before(r).remove();
   219 						$('#edit-'+id).before(r).remove();
   220 
   220 						$(inlineEditPost.what+id).hide().fadeIn();
   221 						var row = $(inlineEditPost.what+id);
       
   222 						row.hide();
       
   223 
       
   224 						if ( 'draft' == $('input[name="post_status"]').val() )
       
   225 							row.find('td.column-comments').hide();
       
   226 
       
   227 						inlineEditPost.addEvents(row);
       
   228 						row.fadeIn();
       
   229 					} else {
   221 					} else {
   230 						r = r.replace( /<.[^<>]*?>/g, '' );
   222 						r = r.replace( /<.[^<>]*?>/g, '' );
   231 						$('#edit-'+id+' .inline-edit-save').append('<span class="error">'+r+'</span>');
   223 						$('#edit-'+id+' .inline-edit-save').append('<span class="error">'+r+'</span>');
   232 					}
   224 					}
   233 				} else {
   225 				} else {