Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function renderCategoriesListForAddition(parentCategory_ID, containerID){
- var parentCategory = CategoriesManager.requestCategoryByID(parentCategory_ID);
- parentCategory.done(function(category){
- parentCategory = category;
- });
- var call = CategoriesManager.requestListOfCategories(parentCategory_ID);
- call.done(function(categoriesList){
- $('#'+containerID).html('<ons-list-header>Choose the destination of your new category</ons-list-header>');
- var addHere = '<ons-list-item tappable onclick="insertCategory(\''+parentCategory_ID+'\', \''+containerID+'\')">';
- addHere += '<div class="left">';
- addHere += '<ons-icon icon="md-plus"></ons-icon>';
- addHere += '</div>';
- addHere += '<div class="center">';
- addHere += 'Add Here';
- addHere += '</div>';
- addHere += '</ons-list-item>';
- if(parentCategory_ID){
- if(!parentCategory.parentCategory_ID){
- parentCategory.parentCategory_ID = '';
- }
- var onclick = "renderCategoriesListForAddition('"+parentCategory.parentCategory_ID+"', '"+containerID+"')";
- var goBack = '<ons-list-item tappable onclick="'+onclick+'">';
- goBack += '<div class="left">';
- goBack += '';
- goBack += '</div>';
- goBack += '<div class="center">'+parentCategory.name+'</div>';
- goBack += '</ons-list-item>';
- $('#'+containerID).append(goBack);
- }
- $('#'+containerID).append(addHere);
- for(var i = 0; i < categoriesList.length; i++){
- appendListItem(categoriesList[i], containerID);
- }
- });
- var appendListItem = function(category, containerID){
- $('#'+containerID).append(getListItem(category));
- }
- var getListItem = function(category){
- var result = '';
- result += '<ons-list-item modifier="chevron" tappable ';
- result += 'onclick="renderCategoriesListForAddition(\''+category.ID+'\', \''+containerID+'\')"> ';
- result += '<div class="left"></div>'
- result += '<div class="center">';
- result += category.name;
- result += '</div>';
- result += '</ons-list-item>';
- return result;
- }
- }
- function insertCategory(parentCategory_ID, containerID){
- ons.notification.prompt({
- title: 'New Category',
- message: 'Enter a name for your new category',
- cancelable: 'cancelable'
- }).then(function(categoryName){
- if(!categoryName){
- ons.notification.alert({
- title: 'Error',
- message: 'Category name cannot be empty'
- });
- } else {
- var addition = CategoriesManager.saveCategory(categoryName, '', parentCategory_ID, '');
- addition.done(function(category){
- ons.notification.alert({
- title: 'Success',
- message: 'Your new category has been added'
- }).then(function(){
- if(!parentCategory_ID){
- parentCategory_ID = ''; // make sure it's exactly an empty string
- }
- renderCategoriesListForAddition(parentCategory_ID, containerID);
- });
- });
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement