Permalink
Browse files

add custom fields creator api to git

  • Loading branch information...
0 parents commit 09b0bacda38b017ad7dfaf690b3885ec2033a42a @madalinungureanu committed Oct 24, 2011
@@ -0,0 +1,75 @@
+#mb-ajax-loading{
+ position:absolute;
+ top:0;
+ left:0;
+ width:100%;
+ height:100%;
+ background:url(images/ajax-loader.gif) center center no-repeat; z-index:999;
+}
+
+.mbedit span{
+ padding:0px 5px;
+ background:url(images/settings.png) center center no-repeat;
+}
+.mbdelete span{
+ padding:0px 5px;
+ background:url(images/delete.png) center center no-repeat;
+}
+.mbadd{
+ display:inline-block !important;
+ padding:10px 20px !important;
+}
+.mbadd span{
+ padding:0px 5px;
+ background:url(images/plus.png) center center no-repeat;
+}
+.mbupdate{
+ display:inline-block !important;
+ padding:10px 20px !important;
+}
+.mbupdate span{
+ padding:2px 8px;
+ background:url(images/save.png) center center no-repeat;
+}
+
+.mb-list-entry-fields{
+ list-style:none;
+}
+
+.mb-table-container tr:nth-child(2n+1) {
+ background-color:#FCFCFC;
+}
+
+.mb-table-container tr:last-child td {
+ border-bottom: 0 none;
+}
+
+.mb-table-container tr td {
+ background: none repeat scroll 0 0 transparent;
+ border-bottom: 1px solid #EDEDED;
+ border-right: 1px solid #EDEDED;
+ padding: 8px;
+ position: relative;
+}
+
+.mb-table-container tr td:last-child {
+ border-right: 0 none;
+}
+
+.mb-table-container thead > tr > th {
+ border-right: 1px solid #E1E1E1;
+}
+
+.mb-table-container tr > th:last-child {
+ border-right: 0 none;
+}
+
+.mb-textarea{
+ width:60%;
+ max-width:600px;
+ height:130px;
+}
+.mb-text-input{
+ width:40%;
+ max-width:400px;
+}
@@ -0,0 +1,164 @@
+/* Add width to elements at startup */
+jQuery(function(){
+ jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() });
+});
+
+/* add reccord to the meta */
+function addMeta(value, id, nonce){
+ jQuery('#'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append('<div id="mb-ajax-loading"></div>');
+ /*object to hold the values */
+ var values = {};
+
+ jQuery('#'+value+' .mb-field').each(function(){
+ var key = jQuery(this).attr('name');
+ values[key.toString()] = jQuery(this).val().toString();
+ });
+
+ jQuery.post( ajaxurl , { action:"cfc_add_meta", meta:value, id:id, values:values, _ajax_nonce:nonce}, function(response) {
+ //alert(response);
+ /* refresh the list */
+ jQuery.post( ajaxurl , { action:"cfc_refresh_list"+value, meta:value, id:id}, function(response) {
+
+ jQuery('#container_'+value).replaceWith(response);
+
+ jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() });
+
+ if( !jQuery( '#'+value ).hasClass('single') )
+ mb_sortable_elements();
+
+ jQuery('#'+value+' .mb-field').each(function(){
+ jQuery(this).val('');
+ });
+ jQuery('#'+value).parent().css('opacity','1');
+
+ /* Remove form if is single */
+ if( jQuery( '#'+value ).hasClass('single') )
+ jQuery( '#'+value ).remove();
+
+ jQuery('#mb-ajax-loading').remove();
+ });
+ });
+}
+
+/* remove reccord from the meta */
+function removeMeta(value, id, element_id, nonce){
+
+ var response = confirm( "Delete this item ?" );
+
+ if( response == true ){
+
+ jQuery('#'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append('<div id="mb-ajax-loading"></div>');
+ jQuery.post( ajaxurl , { action:"cfc_remove_meta", meta:value, id:id, element_id:element_id, _ajax_nonce:nonce}, function(response) {
+
+ /* If single add the form */
+ if( jQuery( '#container_'+value ).hasClass('single') ){
+ jQuery.post( ajaxurl , { action:"cfc_add_form"+value, meta:value, id:id }, function(response) {
+ jQuery( '#container_'+value ).before( response );
+ jQuery( '#'+value ).addClass('single');
+ });
+ }
+
+ /* refresh the list */
+ jQuery.post( ajaxurl , { action:"cfc_refresh_list"+value, meta:value, id:id}, function(response) {
+ jQuery('#container_'+value).replaceWith(response);
+
+ jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() });
+
+ mb_sortable_elements();
+ jQuery('#'+value).parent().css('opacity','1');
+ jQuery('#mb-ajax-loading').remove();
+ });
+
+ });
+ }
+}
+
+/* swap two reccords */
+/*function swapMetaMb(value, id, element_id, swap_with){
+ jQuery('#'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append('<div id="mb-ajax-loading"></div>');
+ jQuery.post( ajaxurl , { action:"swap_meta_mb", meta:value, id:id, element_id:element_id, swap_with:swap_with}, function(response) {
+
+ jQuery.post( ajaxurl , { action:"refresh_list", meta:value, id:id}, function(response) {
+ jQuery('#container_'+value).replaceWith(response); jQuery('#'+value).parent().css('opacity','1'); jQuery('#mb-ajax-loading').remove();
+ });
+
+ });
+}
+*/
+
+/* reorder elements through drag and drop */
+function mb_sortable_elements() {
+ jQuery( ".mb-table-container tbody" ).not( jQuery( ".mb-table-container.single tbody" ) ).sortable({
+ update: function(event, ui){
+
+ var value = jQuery(".mb-table-container").prev().attr('id');
+ var id = jQuery(".mb-table-container").attr('post');
+
+ var result = jQuery(".mb-table-container tbody").sortable('toArray');
+
+ var values = {};
+ for(var i in result)
+ {
+ values[i] = result[i].replace('element_','');
+ }
+
+ jQuery('#'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append('<div id="mb-ajax-loading"></div>');
+
+ jQuery.post( ajaxurl , { action:"cfc_reorder_meta", meta:value, id:id, values:values}, function(response) {
+ jQuery.post( ajaxurl , { action:"cfc_refresh_list"+value, meta:value, id:id}, function(response) {
+ jQuery('#container_'+value).replaceWith(response);
+
+ jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() });
+
+ mb_sortable_elements();
+ jQuery('#'+value).parent().css('opacity','1');
+ jQuery('#mb-ajax-loading').remove();
+ });
+
+ });
+ }
+ });
+ jQuery( "#sortable" ).disableSelection();
+}
+jQuery(mb_sortable_elements);
+
+
+
+/* show the update form */
+function showUpdateFormMeta(value, id, element_id, nonce){
+ jQuery('#'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append('<div id="mb-ajax-loading"></div>');
+
+ jQuery( ".mb-table-container tbody" ).sortable("disable");
+
+ jQuery.post( ajaxurl , { action:"cfc_show_update"+value, meta:value, id:id, element_id:element_id, _ajax_nonce:nonce}, function(response) {
+ //jQuery('#container_'+value+' #element_'+element_id).append(response);
+ jQuery(response).insertAfter('#container_'+value+' #element_'+element_id);
+ jQuery('#'+value).parent().css('opacity','1');
+ jQuery('#mb-ajax-loading').remove();
+ });
+}
+
+/* update reccord */
+function updateMeta(value, id, element_id, nonce){
+ jQuery('#'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append('<div id="mb-ajax-loading"></div>');
+ var values = {};
+ jQuery('#update_container_'+value+'_'+element_id+' .mb-field').each(function(){
+ var key = jQuery(this).attr('name');
+ values[key.toString()] = jQuery(this).val().toString();
+ });
+
+ jQuery.post( ajaxurl , { action:"cfc_update_meta", meta:value, id:id, element_id:element_id, values:values, _ajax_nonce:nonce}, function(response) {
+ jQuery('#update_container_'+value+'_'+element_id).remove();
+ /* refresh the list */
+ jQuery.post( ajaxurl , { action:"cfc_refresh_list"+value, meta:value, id:id}, function(response) {
+ jQuery('#container_'+value).replaceWith(response);
+
+ jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() });
+
+ mb_sortable_elements();
+ jQuery('#'+value).parent().css('opacity','1');
+ jQuery('#mb-ajax-loading').remove();
+ });
+
+ });
+}
Oops, something went wrong.

0 comments on commit 09b0bac

Please sign in to comment.