Advertisement
Guest User

selectPostCategory

a guest
Apr 17th, 2017
44
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 2.58 KB | None
  1. var post_ID;
  2. function renderCategoriesListForSelection(parentCategory_ID, aPost_ID){
  3.     post_ID = aPost_ID;
  4.     var parentCategory = CategoriesManager.requestCategoryByID(parentCategory_ID);
  5.     parentCategory.done(function(category){
  6.         parentCategory = category;
  7.     });
  8.     var call = CategoriesManager.requestListOfCategories(parentCategory_ID);
  9.     call.done(function(categoriesList){
  10.         $('#categoriesList').html('<ons-list-header>Choose where you want to add this post</ons-list-header>');
  11.         var selectHere = '<ons-list-item tappable onclick="setPostCategory(\''+parentCategory_ID+'\', \''+post_ID+'\')">';
  12.         selectHere += '<div class="left">';
  13.         selectHere += '<ons-icon icon="md-plus"></ons-icon>';
  14.         selectHere += '</div>';
  15.         selectHere += '<div class="center">';
  16.         selectHere += 'Add Here ('+parentCategory.name+')';
  17.         selectHere += '</div>';
  18.         selectHere += '</ons-list-item>';
  19.    
  20.             if(!parentCategory.parentCategory_ID){
  21.                 parentCategory.parentCategory_ID = '';
  22.             }
  23.             var onclick = "renderCategoriesListForSelection('"+parentCategory.parentCategory_ID+"', '"+post_ID+"')";
  24.             var goBack = '<ons-list-item tappable onclick="'+onclick+'">';
  25.             goBack += '<div class="left">';
  26.             goBack += '';
  27.             goBack += '</div>';
  28.             goBack += '<div class="center">'+parentCategory.name+'</div>';
  29.             goBack += '</ons-list-item>';
  30.             $('#categoriesList').append(goBack);           
  31.         if(!parentCategory.category_ID){
  32.             $('#categoriesList').append(selectHere);
  33.         }
  34.         for(var i = 0; i < categoriesList.length; i++){
  35.             appendListItem(categoriesList[i]);     
  36.         }
  37.  
  38.     });
  39.    
  40.     var appendListItem = function(category){
  41.         $('#categoriesList').append(getListItem(category));
  42.     }
  43.    
  44.     var getListItem = function(category){
  45.         var result = '';
  46.         result += '<ons-list-item modifier="chevron" tappable ';
  47.         result += 'onclick="renderCategoriesListForSelection(\''+category.ID+'\', \''+post_ID+'\')"> ';
  48.        
  49.         result += '<div class="left"></div>';
  50.         result += '<div class="center">';
  51.         result += category.name;
  52.         result += '</div>';
  53.         result += '</ons-list-item>';
  54.         return result;
  55.     }
  56.    
  57.  
  58. }
  59.  
  60.  function setPostCategory(parentCategory_ID, post_ID){
  61.     var post = PostsManager.requestPostByID(post_ID);
  62.     var parentCategory = CategoriesManager.requestCategoryByID(parentCategory_ID);
  63.     post.done(function(aPost){
  64.         post = aPost;
  65.         parentCategory.done(function(aCategory){
  66.             parentCategory = aCategory;        
  67.             //title, text, category_ID, post_ID
  68.             var call = PostsManager.savePost(post.title, post.text, parentCategory_ID, post.ID);
  69.             call.done(function(post){
  70.                 fn.load('menu/categories/main.html');
  71.             });
  72.            
  73.         });
  74.     });
  75.  }
Advertisement
RAW Paste Data Copied
Advertisement