Browse Source

Fixing delete icon. Adding download folder.

Julio Montoya 11 years ago
parent
commit
bca672d08d
4 changed files with 228 additions and 160 deletions
  1. 40 64
      main/inc/lib/display.lib.php
  2. 76 8
      main/template/default/layout/head.tpl
  3. 22 16
      main/work/work.lib.php
  4. 90 72
      main/work/work.php

+ 40 - 64
main/inc/lib/display.lib.php

@@ -875,9 +875,10 @@ class Display {
         $width_fix = false
     ) {
         $obj = new stdClass();
+        $obj->first = 'first';
 
         if (!empty($url)) {
-            $obj->url       = $url;
+            $obj->url = $url;
         }
 
         //This line should only be used/modified in case of having characters
@@ -887,12 +888,12 @@ class Display {
         $obj->colNames      = $column_names;
         $obj->colModel      = $column_model;
         $obj->pager         = '#'.$div_id.'_pager';
-
         $obj->datatype  = 'json';
+        $obj->viewrecords = 'true';
 
         $all_value = 10000000;
 
-        //Default row quantity
+        // Default row quantity
         if (!isset($extra_params['rowList'])) {
             $extra_params['rowList'] = array(20, 50, 100, 500, 1000, $all_value);
         }
@@ -902,16 +903,16 @@ class Display {
             $obj->datatype  = $extra_params['datatype'];
         }
 
-        //Row even odd style
+        // Row even odd style.
         $obj->altRows = true;
         if (!empty($extra_params['altRows'])) {
-            $obj->altRows      = $extra_params['altRows'];
+            $obj->altRows = $extra_params['altRows'];
         }
 
         if (!empty($extra_params['sortname'])) {
             $obj->sortname      = $extra_params['sortname'];
         }
-        //$obj->sortorder     = 'desc';
+
         if (!empty($extra_params['sortorder'])) {
             $obj->sortorder     = $extra_params['sortorder'];
         }
@@ -925,18 +926,24 @@ class Display {
             $obj->rowNum     = $extra_params['rowNum'];
         }
 
-        $obj->viewrecords = 'true';
-
-        if (!empty($extra_params['viewrecords']))
+        if (!empty($extra_params['viewrecords'])) {
             $obj->viewrecords   = $extra_params['viewrecords'];
+        }
 
+        $beforeSelectRow = null;
+        if (isset($extra_params['beforeSelectRow'])) {
+            $beforeSelectRow = "beforeSelectRow: ".$extra_params['beforeSelectRow'].", ";
+            unset($extra_params['beforeSelectRow']);
+        }
+
+        // Adding extra params
         if (!empty($extra_params)) {
-            foreach ($extra_params as $key=>$element){
+            foreach ($extra_params as $key => $element) {
                 $obj->$key = $element;
             }
         }
 
-        //Adding static data
+        // Adding static data.
         if (!empty($data)) {
             $data_var = $div_id.'_data';
             $json.=' var '.$data_var.' = '.json_encode($data).';';
@@ -945,80 +952,49 @@ class Display {
             $json.="\n";
         }
 
+        $obj->end = 'end';
+
         $json_encode = json_encode($obj);
 
         if (!empty($data)) {
             //Converts the "data":"js_variable" to "data":js_variable othersiwe it will not work
-            $json_encode = str_replace('"data":"'.$data_var.'"','"data":'.$data_var.'',$json_encode);
+            $json_encode = str_replace('"data":"'.$data_var.'"', '"data":'.$data_var.'', $json_encode);
         }
 
-        //Fixing true/false js values that doesn't need the ""
+        // Fixing true/false js values that doesn't need the ""
         $json_encode = str_replace(':"true"',':true',$json_encode);
-        //wrap_cell is not a valid jqgrid attributes is a hack to wrap a text
-        $json_encode = str_replace('"wrap_cell":true','cellattr : function(rowId, value, rowObject, colModel, arrData) { return \'class = "jqgrid_whitespace"\'; }', $json_encode);
+        // wrap_cell is not a valid jqgrid attributes is a hack to wrap a text
+        $json_encode = str_replace('"wrap_cell":true', 'cellattr : function(rowId, value, rowObject, colModel, arrData) { return \'class = "jqgrid_whitespace"\'; }', $json_encode);
         $json_encode = str_replace(':"false"',':false',$json_encode);
-        $json_encode = str_replace('"formatter":"action_formatter"','formatter:action_formatter',$json_encode);
-
-        if ($width_fix) {
-            if (is_numeric($width_fix)) {
-                $width_fix = intval($width_fix);
-            } else {
-                $width_fix = '150';
-            }
-            //see BT#2020
-            /*$json .= "$(window).bind('resize', function() {
-                $('#".$div_id."').setGridWidth($(window).width() - ".$width_fix.");
-            }).trigger('resize');";*/
-        }
+        $json_encode = str_replace('"formatter":"action_formatter"', 'formatter:action_formatter', $json_encode);
+        $json_encode = str_replace(array('{"first":"first",','"end":"end"}'), '', $json_encode);
 
-        //Creating the jqgrid element
-        $json .= '$("#'.$div_id.'").jqGrid(';
+        // Creating the jqgrid element.
+        $json .= '$("#'.$div_id.'").jqGrid({';
+        //$json .= $beforeSelectRow;
         $json .= $json_encode;
-        $json .= ');';
+        $json .= '});';
 
         $all_text = addslashes(get_lang('All'));
         $json .= '$("'.$obj->pager.' option[value='.$all_value.']").text("'.$all_text.'");';
-
-        $json.="\n";
-
-        //Adding edit/delete icons
-        $json.=$formatter;
+        $json.= "\n";
+        // Adding edit/delete icons.
+        $json.= $formatter;
 
         return $json;
-
-        /*
-        Real Example
-        $("#list_week").jqGrid({
-            url:'<?php echo api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=session_courses_lp_by_week&session_id='.$session_id; ?>',
-            datatype: 'json',
-            colNames:['Week','Date','Course', 'LP'],
-            colModel :[
-              {name:'week',     index:'week',   width:120, align:'right'},
-              {name:'date',     index:'date',   width:120, align:'right'},
-              {name:'course',   index:'course', width:150},
-              {name:'lp',       index:'lp',     width:250}
-            ],
-            pager: '#pager3',
-            rowNum:100,
-             rowList:[10,20,30],
-            sortname: 'date',
-            sortorder: 'desc',
-            viewrecords: true,
-            grouping:true,
-            groupingView : {
-                groupField : ['week'],
-                groupColumnShow : [false],
-                groupText : ['<b>Week {0} - {1} Item(s)</b>']
-            }
-        });  */
     }
 
+    /**
+     * @param array $headers
+     * @param array $rows
+     * @param array $attributes
+     * @return string
+     */
     public static function table($headers, $rows, $attributes = array()) {
 
     	if (empty($attributes)) {
     		$attributes['class'] = 'data_table';
-    	}
-        //require_once api_get_path(LIBRARY_PATH).'pear/HTML/Table.php';
+        }
         $table = new HTML_Table($attributes);
         $row = 0;
         $column = 0;

+ 76 - 8
main/template/default/layout/head.tpl

@@ -194,6 +194,68 @@ $(document).scroll(function() {
     }
 });
 
+function showConfirmationPopup(obj, urlParam)
+{
+    if (urlParam) {
+        url = urlParam
+    } else {
+        url = obj.href;
+    }
+
+    var dialog  = $("#dialog");
+    if ($("#dialog").length == 0) {
+        dialog  = $('<div id="dialog" style="display:none">{{ "ConfirmYourChoice" | get_lang }} </div>').appendTo('body');
+    }
+
+    var width_value = 350;
+    var height_value = 150;
+    var resizable_value = true;
+
+    var new_param = get_url_params(url, 'width');
+    if (new_param) {
+        width_value = new_param;
+    }
+
+    var new_param = get_url_params(url, 'height')
+    if (new_param) {
+        height_value = new_param;
+    }
+
+    var new_param = get_url_params(url, 'resizable');
+    if (new_param) {
+        resizable_value = new_param;
+    }
+
+    // Show dialog
+    dialog.dialog({
+        modal       : true,
+        width       : width_value,
+        height      : height_value,
+        resizable   : resizable_value,
+        buttons: [
+            {
+                text: '{{ 'Yes' | get_lang }}',
+                click: function() {
+                    window.location = url;
+                },
+                icons:{
+                    primary:'ui-icon-locked'
+                }
+            },
+            {
+                text: '{{ 'No' | get_lang }}',
+                click: function() { $(this).dialog("close"); },
+                icons:{
+                    primary:'ui-icon-locked'
+                }
+            }
+        ]
+    });
+    console.log('dd');
+    // prevent the browser to follow the link
+    return false;
+}
+
 $(function() {
 
     check_brand();
@@ -237,21 +299,21 @@ $(function() {
             dialog  = $('<div id="dialog" style="display:none"></div>').appendTo('body');
         }
 
-        width_value = 580;
-        height_value = 450;
-        resizable_value = true;
+        var width_value = 580;
+        var height_value = 450;
+        var resizable_value = true;
 
-        new_param = get_url_params(url, 'width');
+        var new_param = get_url_params(url, 'width');
         if (new_param) {
             width_value = new_param;
         }
 
-        new_param = get_url_params(url, 'height')
+        var new_param = get_url_params(url, 'height')
         if (new_param) {
             height_value = new_param;
         }
 
-        new_param = get_url_params(url, 'resizable');
+        var new_param = get_url_params(url, 'resizable');
         if (new_param) {
             resizable_value = new_param;
         }
@@ -269,11 +331,17 @@ $(function() {
                 });
             }
         );
-        //prevent the browser to follow the link
+        // prevent the browser to follow the link
+        return false;
+    });
+
+    // Global confirmation
+    $('.popup-confirmation').on('click', function() {
+        showConfirmationPopup(this);
         return false;
     });
 
-    //old jquery.menu.js
+    // old jquery.menu.js
     $('#navigation a').stop().animate({
         'marginLeft':'50px'
     },1000);

+ 22 - 16
main/work/work.lib.php

@@ -118,7 +118,7 @@ function settingsForm($defaults)
     $form->addGroup($group, '', get_lang('StudentAllowedToDeleteOwnPublication'));
     $form->addElement('button', 'submit', get_lang('Save'));
     $form->setDefaults($defaults);
-    $form->display();
+    return $form->return_form();
 }
 
 /**
@@ -749,21 +749,11 @@ function showTeacherWorkGrid()
         array('name'=>'title', 'index'=>'title',  'width'=>'300',   'align'=>'left'),
         array('name'=>'expires_on', 'index'=>'expires_on', 'width'=>'150',  'align'=>'left'),
         array('name'=>'end_on', 'index'=>'end_on', 'width'=>'150',  'align'=>'left'),
-        array('name'=>'actions', 'index'=>'actions', 'width'=>'150', 'align'=>'left', 'formatter'=>'action_formatter', 'sortable'=>'false')
+        array('name'=>'actions', 'index'=>'actions', 'width'=>'150', 'align'=>'left', 'sortable'=>'false')
     );
-
     $token = null;
-    $baseUrl = api_get_path(WEB_CODE_PATH).'work/';
-    $action_links = 'function action_formatter(cellvalue, options, rowObject) {
-    return \'<a href="'.$baseUrl.'edit_work.php?'.api_get_cidreq().'&id=\'+options.rowId+\'">'.
-        Display::return_icon('edit.png', get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'.
-        '&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="'.$baseUrl.'work.php?'.api_get_cidreq().'&action=delete_dir&id=\'+options.rowId+\'">'.
-        Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'.
-        '\';
-    }';
 
     $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_work_teacher&'.api_get_cidreq();
-
     $deleteUrl = api_get_path(WEB_AJAX_PATH).'work.ajax.php?a=delete_work&'.api_get_cidreq();
 
     $columns = array(
@@ -777,13 +767,13 @@ function showTeacherWorkGrid()
     $params = array(
         'multiselect' => true,
         'autowidth' => 'true',
-        'height' => 'auto'
+        'height' => 'auto',
+        //'beforeSelectRow' => 'function(rowid, e) { e.stopPropagation(); }'
     );
 
     $html = '<script>
     $(function() {
-        '.Display::grid_js('workList', $url, $columns, $columnModel, $params, array(), $action_links, true).'
-
+        '.Display::grid_js('workList', $url, $columns, $columnModel, $params, array(), null, true).'
         $("#workList").jqGrid(
             "navGrid",
             "#workList_pager",
@@ -1654,13 +1644,29 @@ function getWorkListTeacher($start, $limit, $column, $direction, $where_conditio
         $works = array();
         $url = api_get_path(WEB_CODE_PATH).'work/work_list_all.php?'.api_get_cidreq();
         while ($work = Database::fetch_array($result, 'ASSOC')) {
+            $workId = $work['id'];
             $work['type'] = Display::return_icon('work.png');
             $work['expires_on'] = $work['expires_on']  == '0000-00-00 00:00:00' ? null : api_get_local_time($work['expires_on']);
             $work['ends_on'] = $work['ends_on']  == '0000-00-00 00:00:00' ? null : api_get_local_time($work['ends_on']);
             if (empty($work['title'])) {
                 $work['title'] = basename($work['url']);
             }
-            $work['title'] = Display::url($work['title'], $url.'&id='.$work['id']);
+            $work['title'] = Display::url($work['title'], $url.'&id='.$workId);
+
+            $editLink = Display::url(
+                Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL),
+                api_get_path(WEB_CODE_PATH).'work/edit_work.php?id='.$workId.'&'.api_get_cidreq()
+            );
+
+            $downloadLink = Display::url(
+                Display::return_icon('save_pack.png', get_lang('Save'), array(), ICON_SIZE_SMALL),
+                api_get_path(WEB_CODE_PATH).'work/downloadfolder.inc.php?id='.$workId.'&'.api_get_cidreq()
+            );
+            $deleteUrl = api_get_path(WEB_CODE_PATH).'work/work.php?id='.$workId.'&action=delete_dir&'.api_get_cidreq();
+            $deleteLink = '<a href="#" onclick="showConfirmationPopup(this, \''.$deleteUrl.'\' ) " >'.
+                Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL).'</a>';
+
+            $work['actions'] = $downloadLink.$editLink.$deleteLink;
             $works[] = $work;
         }
     }

+ 90 - 72
main/work/work.php

@@ -6,6 +6,8 @@
 
 /* INIT SECTION */
 
+use ChamiloSession as Session;
+
 $language_file = array('exercice', 'work', 'document', 'admin', 'gradebook');
 
 require_once '../inc/global.inc.php';
@@ -119,7 +121,6 @@ if (!empty($group_id)) {
     if ($action == 'create_dir') {
         $interbreadcrumb[] = array ('url' => 'work.php','name' => get_lang('CreateAssignment'));
     }
-    Display::display_header(null);
 } else {
     if (isset($origin) && $origin != 'learnpath') {
 
@@ -140,10 +141,6 @@ if (!empty($group_id)) {
         if ($action == 'create_dir') {
             $interbreadcrumb[] = array ('url' => '#','name' => get_lang('CreateAssignment'));
         }
-        Display :: display_header(null);
-    } else {
-        //we are in the learnpath tool
-        Display::display_reduced_header();
     }
 }
 
@@ -153,69 +150,83 @@ event_access_tool(TOOL_STUDENTPUBLICATION);
 $is_allowed_to_edit = api_is_allowed_to_edit();
 $student_can_edit_in_session = api_is_allowed_to_session_edit(false, true);
 
-Display::display_introduction_section(TOOL_STUDENTPUBLICATION);
-
-if ($origin == 'learnpath') {
-    echo '<div style="height:15px">&nbsp;</div>';
-}
-
 /*	Display links to upload form and tool options */
 if (!in_array($action, array('add', 'create_dir'))) {
     $token = Security::get_token();
 }
 $courseInfo = api_get_course_info();
-display_action_links($work_id, $curdirpath, $action);
+
+$currentUrl = api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq();
+$content = null;
+
 // For teachers
 switch ($action) {
     case 'settings':
         //if posts
         if ($is_allowed_to_edit && !empty($_POST['changeProperties'])) {
             updateSettings($course, $_POST['show_score'], $_POST['student_delete_own_publication']);
-            Display::display_confirmation_message(get_lang('Saved'));
+            Session::write('message', Display::return_message(get_lang('Saved'), 'success'));
+            header('Location: '.$currentUrl);
+            exit;
         }
         $studentDeleteOwnPublication = api_get_course_setting('student_delete_own_publication') == 1 ? 1 : 0;
         /*	Display of tool options */
-        settingsForm(
+        $content = settingsForm(
             array(
                 'show_score' => $course_info['show_score'],
                 'student_delete_own_publication' =>  $studentDeleteOwnPublication
             )
         );
         break;
-    case 'mark_work':
-        if (!api_is_allowed_to_edit()) {
-            echo Display::return_message(get_lang('ActionNotAllowed'), 'error');
-            Display::display_footer();
-        }
-        break;
-    case 'create_dir':
     case 'add':
-        // Show them the form for the directory name
-        if ($is_allowed_to_edit && in_array($action, array('create_dir', 'add'))) {
-
-            $form = new FormValidator('form1', 'post', api_get_path(WEB_CODE_PATH).'work/work.php?action=create_dir&'. api_get_cidreq());
-            $form->addElement('header', get_lang('CreateAssignment'));
-            $form->addElement('hidden', 'action', 'add');
-            $form = getFormWork($form, array());
-            $form->addElement('style_submit_button', 'submit', get_lang('CreateDirectory'));
-
-            if ($form->validate()) {
-                $result = addDir($_POST, $user_id, $_course, $group_id, $id_session);
-                if ($result) {
-                    Display::display_confirmation_message(get_lang('DirectoryCreated'), false);
-                } else {
-                    Display::display_error_message(get_lang('CannotCreateDir'));
-                }
+    case 'create_dir':
+        if (!$is_allowed_to_edit) {
+            api_not_allowed();
+        }
+        $form = new FormValidator('form1', 'post', api_get_path(WEB_CODE_PATH).'work/work.php?action=create_dir&'. api_get_cidreq());
+        $form->addElement('header', get_lang('CreateAssignment'));
+        $form->addElement('hidden', 'action', 'add');
+        $form = getFormWork($form, array());
+        $form->addElement('style_submit_button', 'submit', get_lang('CreateDirectory'));
+
+        if ($form->validate()) {
+            $result = addDir($_POST, $user_id, $_course, $group_id, $id_session);
+            if ($result) {
+                $message = Display::return_message(get_lang('DirectoryCreated'), 'success');
             } else {
-                $form->display();
+                $message = Display::return_message(get_lang('CannotCreateDir'), 'error');
             }
+
+            Session::write('message', $message);
+            header('Location: '.$currentUrl);
+            exit;
+        } else {
+            $content = $form->return_form();
         }
+        break;
     case 'delete_dir':
+        if ($is_allowed_to_edit) {
+            $work_to_delete = get_work_data_by_id($_REQUEST['id']);
+            $result = deleteDirWork($_REQUEST['id']);
+            if ($result) {
+                $message = Display::return_message(get_lang('DirDeleted') . ': '.$work_to_delete['title'], 'success');
+                Session::write('message', $message);
+                header('Location: '.$currentUrl);
+                exit;
+            }
+        }
+        break;
     case 'move':
+        /*	Move file form request */
+        if ($is_allowed_to_edit) {
+            if (!empty($item_id)) {
+                $content = generateMoveForm($item_id, $curdirpath, $course_info, $group_id, $session_id);
+            }
+        }
+        break;
     case 'move_to':
-    case 'list':
         /* Move file command */
-        if ($is_allowed_to_edit && $action == 'move_to') {
+        if ($is_allowed_to_edit) {
             $move_to_path = get_work_path($_REQUEST['move_to_id']);
 
             if ($move_to_path==-1) {
@@ -226,42 +237,28 @@ switch ($action) {
 
             // Security fix: make sure they can't move files that are not in the document table
             if ($path = get_work_path($item_id)) {
-
                 if (move($course_dir.'/'.$path, $base_work_dir . $move_to_path)) {
                     // Update db
                     updateWorkUrl($item_id, 'work' . $move_to_path, $_REQUEST['move_to_id']);
                     api_item_property_update($_course, 'work', $_REQUEST['move_to_id'], 'FolderUpdated', $user_id);
 
-                    Display::display_confirmation_message(get_lang('DirMv'));
+                    $message = Display::return_message(get_lang('DirMv'), 'success');
                 } else {
-                    Display::display_error_message(get_lang('Impossible'));
+                    $message = Display::return_message(get_lang('Impossible'), 'error');
                 }
             } else {
-                Display :: display_error_message(get_lang('Impossible'));
-            }
-        }
-
-        /*	Move file form request */
-        if ($is_allowed_to_edit && $action == 'move') {
-            if (!empty($item_id)) {
-                echo generateMoveForm($item_id, $curdirpath, $course_info, $group_id, $session_id);
-            }
-        }
-
-        /*	Delete dir */
-
-        if ($is_allowed_to_edit && $action == 'delete_dir') {
-            $work_to_delete = get_work_data_by_id($_REQUEST['id']);
-            $result = deleteDirWork($_REQUEST['id']);
-
-            if ($result) {
-                Display::display_confirmation_message(get_lang('DirDeleted') . ': '.$work_to_delete['title']);
+                $message = Display::return_message(get_lang('Impossible'), 'error');
             }
+            Session::write('message', $message);
+            header('Location: '.$currentUrl);
+            exit;
         }
+        break;
+    case 'list':
 
         /*	Display list of student publications */
         if (!empty($my_folder_data['description'])) {
-            echo '<p><div><strong>'.
+            $content = '<p><div><strong>'.
                 get_lang('Description').':</strong><p>'.Security::remove_XSS($my_folder_data['description'], STUDENT).
                 '</p></div></p>';
         }
@@ -277,19 +274,40 @@ switch ($action) {
             $userList = getWorkUserList($course_code, $session_id);
 
             // Work list
-            echo '<div class="row">';
-            echo '<div class="span9">';
-            $grid = showTeacherWorkGrid();
-            echo $grid ;
-            echo '</div>';
-            echo '<div class="span3">';
-            echo showStudentList($userList, $work_parents, $group_id, $course_id, $session_id);
-            echo '</div>';
+            $content .= '<div class="row">';
+            $content .= '<div class="span9">';
+            $content .= showTeacherWorkGrid();
+            $content .= '</div>';
+            $content .= '<div class="span3">';
+            $content .= showStudentList($userList, $work_parents, $group_id, $course_id, $session_id);
+            $content .= '</div>';
         } else {
-            echo showStudentWorkGrid();
+            $content .= showStudentWorkGrid();
         }
     break;
 }
+
+if (isset($origin) && $origin != 'learnpath') {
+    Display :: display_header(null);
+} else {
+    // We are in the learnpath tool
+    Display::display_reduced_header();
+}
+
+Display::display_introduction_section(TOOL_STUDENTPUBLICATION);
+
+if ($origin == 'learnpath') {
+    echo '<div style="height:15px">&nbsp;</div>';
+}
+
+display_action_links($work_id, $curdirpath, $action);
+
+$message = Session::read('message');
+echo $message;
+Session::erase('message');
+
+echo $content;
+
 if ($origin != 'learnpath') {
     //we are not in the learning path tool
     Display :: display_footer();