COSC4606-Assignment-02

Database front end that allows for CRUD operations and user management
git clone git://mattcarlson.org/repos/COSC4606-Assignment-02.git
Log | Files | Refs | README

actions.js (8592B)


      1 /* Show action */
      2 $(document).ready(function() {
      3     $('.action').click(function() {
      4         switch (this.id) {
      5             case 'my_summary': my_summary(this.id);
      6                                break;
      7             case 'view_users': view_users(this.id);
      8                                break;
      9             default:           if (this.id == 'my_courses') ext='php';
     10                                else                         ext='html';
     11 
     12                                /* Actions contained in /actions/ */
     13                                let form = '../actions/' + this.id + '.' + ext;
     14                                /* Load html into main div */
     15                                $('#main').load(form);
     16         }
     17     });
     18 });
     19 
     20 /* Student transcript */
     21 $(document.body).on('submit', '.action_form', function(e) {
     22     /* Don't change page, just in case login fails */
     23     e.preventDefault();
     24 
     25     switch (this.id) {
     26         case 'my_courses_form':           my_courses(this.id);
     27                                           break;
     28 
     29         /* Forms */
     30         case 'add_faculty_form':          add_faculty(this.id);
     31                                           break;
     32         case 'register_student_form':     register_student(this.id);
     33                                           break;
     34         case 'assign_faculty_form':       assign_faculty(this.id);
     35                                           break;
     36         case 'enroll_form':               enroll(this.id);
     37                                           break;
     38         case 'drop_form':                 drop(this.id);
     39                                           break;
     40         case 'change_grade_form':         change_grade(this.id);
     41                                           break;
     42 
     43         /* Reports */
     44         case 'student_transcript_form':   student_transcript(this.id);
     45                                           break;
     46         case 'class_list_form':           class_list(this.id);
     47                                           break;
     48         case 'students_in_degree_form':   students_in_degree(this.id);
     49                                           break;
     50         case 'students_instructors_form': students_instructors(this.id);
     51                                           break;
     52         case 'courses_taught_form':       courses_taught(this.id);
     53                                           break;
     54 
     55         /* Manage Users */
     56         case 'add_user_form':             add_user(this.id);
     57                                           break;
     58         case 'delete_user_form':          delete_user(this.id);
     59                                           break;
     60         case 'modify_user_form':          modify_user(this.id);
     61                                           break;
     62     }
     63 })
     64 
     65 /* Academic summary for students */
     66 function my_summary(task) {
     67    $.post('/php/actions.php', { action : task },
     68        function(url) { open_url(url); }
     69    );
     70 }
     71 
     72 /* Class lists for instructors */
     73 function my_courses(task) {
     74     $.post('/php/actions.php', { action : task,
     75                                  course : $('#course').val() },
     76         function(url) { open_url(url); }
     77     );
     78 }
     79 
     80 /* Forms */
     81 function add_faculty(task) {
     82     $.post('/php/actions.php', { action         : task,
     83                                  faculty_id     : $('#faculty_id').val(),
     84                                  name           : $('#name').val(),
     85                                  surname        : $('#surname').val(),
     86                                  home_phone_num : $('#home_phone_num').val() },
     87         function(msg) { alert(msg); }
     88     );
     89 }
     90 function register_student(task) {
     91     if ($('#coop').attr('type') === 'checkbox' )
     92         is_in_coop = +$('#coop').is(':checked');
     93 
     94     $.post('/php/actions.php', { action     : task,
     95                                  student_id : $('#student_id').val(),
     96                                  name       : $('#name').val(),
     97                                  surname    : $('#surname').val(),
     98                                  phone_num  : $('#phone_num').val(),
     99                                  coop       : is_in_coop,
    100                                  degree     : $('#degree').val() },
    101         function(msg) { alert(msg); }
    102     );
    103 }
    104 function assign_faculty(task) {
    105     $.post('/php/actions.php', { action    : task,
    106                                  faculty_id : $('#faculty_id').val(),
    107                                  code       : $('#code').val(),
    108                                  section    : $('#section').val(),
    109                                  term       : $('#term').val(),
    110                                  year       : $('#year').val() },
    111         function(msg) { alert(msg); }
    112     );
    113 }
    114 function enroll(task) {
    115     $.post('/php/actions.php', { action     : task,
    116                                  student_id : $('#student_id').val(),
    117                                  code       : $('#code').val(),
    118                                  section    : $('#section').val(),
    119                                  term       : $('#term').val(),
    120                                  year       : $('#year').val() },
    121         function(msg) { alert(msg); }
    122     );
    123 }
    124 function drop(task) {
    125     $.post('/php/actions.php', { action     : task,
    126                                  student_id : $('#student_id').val(),
    127                                  code       : $('#code').val(),
    128                                  section    : $('#section').val(),
    129                                  term       : $('#term').val(),
    130                                  year       : $('#year').val() },
    131         function(msg) { alert(msg); }
    132     );
    133 }
    134 function change_grade(task) {
    135     $.post('/php/actions.php', { action : task,
    136                                 student_id : $('#student_id').val(),
    137                                 code       : $('#code').val(),
    138                                 section    : $('#section').val(),
    139                                 term       : $('#term').val(),
    140                                 year       : $('#year').val(),
    141                                 grade      : $('#grade').val() },
    142         function(msg) { alert(msg); }
    143     );
    144 }
    145 
    146 /* Reports */
    147 function class_list(task) {
    148     $.post('/php/actions.php', { action  : task,
    149                                  code    : $('#code').val(),
    150                                  section : $('#section').val(),
    151                                  term    : $('#term').val(),
    152                                  year    : $('#year').val() },
    153         function(url) { open_url(url); }
    154     );
    155 }
    156 function student_transcript(task) {
    157     $.post('/php/actions.php', { action : task,
    158                                  id     : $('#student_id').val() },
    159         function(url) { open_url(url); }
    160     );
    161 }
    162 function students_in_degree(task) {
    163     $.post('/php/actions.php', { action : task,
    164                                  degree : $('#degree').val() },
    165         function(url) { open_url(url); }
    166     );
    167 }
    168 function students_instructors(task) {
    169     $.post('/php/actions.php', { action     : task,
    170                                  student_id : $('#student_id').val(),
    171                                  term       : $('#term').val() },
    172         function(url) { open_url(url); }
    173     );
    174 }
    175 function courses_taught(task) {
    176     $.post('/php/actions.php', { action     : task,
    177                                  faculty_id : $('#faculty_id').val(),
    178                                  term       : $('#term').val() },
    179         function(url) { open_url(url); }
    180     );
    181 }
    182 
    183 /* Manage Users */
    184 function add_user(task) {
    185     $.post('/php/actions.php', { action : task,
    186                                  uid    : $('#uid').val(),
    187                                  user   : $('#user').val(),
    188                                  pwd    : $('#pwd').val(),
    189                                  role   : $('#role').val() },
    190         function(msg) { alert(msg); }
    191     );
    192 }
    193 function delete_user(task) {
    194     $.post('/php/actions.php', { action : task,
    195                                  uid    : $('#uid').val() },
    196         function(msg) { alert(msg); }
    197     );
    198 }
    199 function modify_user(task) {
    200     $.post('/php/actions.php', { action : task,
    201                                  uid    : $('#uid').val(),
    202                                  user   : $('#user').val(),
    203                                  pwd    : $('#pwd').val(),
    204                                  role   : $('#role').val() },
    205         function(msg) { alert(msg); }
    206     );
    207 }
    208 function view_users(task) {
    209     $.post('/php/actions.php', { action : task },
    210         function(url) { open_url(url); }
    211     );
    212 }
    213 
    214 /* Open a url in a new tab */
    215 function open_url(url) {
    216     Object.assign(document.createElement('a'), {
    217     target: '_blank',
    218     href: url,
    219     }).click();
    220 }