kevtrout

topics/group

Feb 2nd, 2012
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. group = {
  2.            
  3.             /*  holds name of current stage 1 opperation in progress
  4.             */
  5.             current_op : false,
  6.            
  7.             /*  defines command aliases
  8.             */
  9.             aliases : {t:'Topic', d:'Delete', e:'Edit'},
  10.            
  11.             /*  sends info to server to modify page content
  12.             *   runs publish command for object functions with response data
  13.             */
  14.             modify : function(){
  15.                 $.post(
  16.                     "<?php echo site_url('topics/groups/modify');?>",
  17.                     {id:command.subject_id,alias:this.current_op.substring(0,1),input:command.received},
  18.                     function(data){
  19.                         group[group.current_op].publish(data);
  20.                         },
  21.                     'json'
  22.                 );
  23.                
  24.             },
  25.            
  26.             /*  sends info to server to add task to group
  27.             *   runs publish command with response html
  28.             */
  29.             create_topic : function(){
  30.                 $.post("<?php echo site_url('topics/topic/create');?>",
  31.                     {id:command.subject_id,alias:this.current_op.substring(0,1),input:command.received},
  32.                     function(data){
  33.                         group.topic.publish(data);
  34.                         },
  35.                     'json'
  36.                 );
  37.             },
  38.            
  39.             /*  deletes groups
  40.             */
  41.             delete : {
  42.                 validate : function(){
  43.                     //if 'enter' was pressed on prompt, delete group
  44.                     if(command.keycode == 13){group.modify();}
  45.                 },
  46.                 prompt : function(){
  47.                     command.prompt('Press enter to confirm delete. [note optional]');
  48.                 },
  49.                 publish : function(data){
  50.                     if(data.response == 'remove')
  51.                         {
  52.                         $('#group_'+command.subject_id).remove();
  53.                         command.prompt('group deleted');
  54.                         }
  55.                     group.conclude();
  56.                 }
  57.             }, 
  58.            
  59.             /*  edits groups
  60.             */
  61.             edit :  {
  62.                 validate : function(){
  63.                     //expects new text to replace old text
  64.                     group.modify();
  65.                    
  66.                 },
  67.                 prompt :  function(){
  68.                     command.prompt('Enter new group name');
  69.                    
  70.                 },
  71.                 publish : function(data){
  72.                     if(data.response == 'edit'){
  73.                         $('#group_'+command.subject_id+' li.group-title').html(data.name);
  74.                         command.prompt('group edited');
  75.                     }
  76.                     else{
  77.                         command.prompt('Error while editing group');
  78.                         }
  79.                     group.conclude();
  80.                    
  81.                 }
  82.             },
  83.            
  84.             /* adds tasks to groups
  85.             */
  86.             topic : {
  87.                 validate : function(){
  88.                     group.create_topic();
  89.                 },
  90.                
  91.                 prompt : function(){
  92.                     command.prompt('Enter topic name then press [enter]');
  93.                 },
  94.                
  95.                 publish : function(data){
  96.                     if(data.response == 'add'){
  97.                         $('#group_'+command.subject_id+' .topics').append(data.html);
  98.                         //recreate sidebar topics so new topic is included
  99.                         layout.sidebar_topics();
  100.                         command.prompt('Task added');
  101.                     }
  102.                     else{
  103.                         command.prompt('Error trying to add topic');
  104.                     }
  105.                     group.conclude();
  106.                 }
  107.             },
  108.             close :{
  109.                 validate : function(){
  110.                     group.modify();
  111.                 },
  112.                
  113.                 prompt : function(){
  114.                     command.prompt('Press enter to verify closure [note optional]');
  115.                 },
  116.                
  117.                 publish : function(data){
  118.                     if(data.response == 'close'){
  119.                         command.prompt('group closed');
  120.                         //remove group from page
  121.                         $('#group_'+command.subject_id).remove();
  122.                     }
  123.                     else{
  124.                         command.prompt('An error occurred while trying to close the group');
  125.                     }
  126.                     group.conclude();
  127.                     }
  128.             },
  129.            
  130.             conclude : function(){
  131.                 command.prompt('Ready...');
  132.                 $('.register').removeClass('marked');
  133.                 group.current_op = false;
  134.                 command.flush();
  135.             }
  136. };
Advertisement
Add Comment
Please, Sign In to add comment