Browse Source

Improvements in the visibility of the homepage tools - (partial DT#5234)

Isaac Flores 15 years ago
parent
commit
01e7e9f3c7
3 changed files with 47 additions and 39 deletions
  1. 16 3
      main/course_home/activity.php
  2. 19 36
      main/course_home/course_home.php
  3. 12 0
      main/inc/lib/main_api.lib.php

+ 16 - 3
main/course_home/activity.php

@@ -376,9 +376,18 @@ function show_tools_category($course_tool_category)
 	Work with data post askable by admin of course (franglais, clean this)
 -----------------------------------------------------------
 */
+
 if (isset($_GET['sent_http_request']) && $_GET['sent_http_request']==1) {
 	if(api_is_allowed_to_edit()) {
 		$tool_table = Database::get_course_table(TABLE_TOOL_LIST);
+		$tool_id = Security::remove_XSS($_GET["id"]);
+		$tool_info = api_get_tool_information($tool_id);
+		$tool_visibility   = $tool_info['visibility'];
+		$tool_image        = $tool_info['image'];
+		$new_image         = str_replace('.gif','_na.gif',$tool_image);
+		$requested_image   = ($tool_visibility == 0 ) ? $tool_image : $new_image;
+		$requested_clase   = ($tool_visibility == 0 ) ? 'visible' : 'invisible';
+		$requested_message = ($tool_visibility == 0 ) ? 'is_active' : 'is_inactive';		
 	 	/*
 		-----------------------------------------------------------
 			HIDE
@@ -390,7 +399,6 @@ if (isset($_GET['sent_http_request']) && $_GET['sent_http_request']==1) {
 				$sql="UPDATE $tool_table SET visibility=0 WHERE id='".$_GET["id"]."'";
 	
 				api_sql_query($sql,__FILE__,__LINE__);
-				echo 'ToolIsNowHidden';
 			}
 		}
 	
@@ -403,9 +411,14 @@ if (isset($_GET['sent_http_request']) && $_GET['sent_http_request']==1) {
 		{
 			if ($_GET["id"]==strval(intval($_GET["id"]))) {
 				api_sql_query("UPDATE $tool_table SET visibility=1 WHERE id='".$_GET["id"]."'",__FILE__,__LINE__);
-				echo 'ToolIsNowVisible';
 			}
 		}
+		$response_data = array(
+			'image'   => $requested_image,
+			'class'   => $requested_clase,
+			'message' => $requested_message
+		);
+		print(json_encode($response_data));
 		exit;
 	}
 } else {
@@ -476,7 +489,7 @@ if(api_is_platform_admin())
 if(api_is_allowed_to_edit())
 {
 	?>
-	<div class="normal-message" id="id_normal_message" style="display:none"><?php echo get_lang("PleaseStandBy")."<br/>"; ?></div>
+	<div class="normal-message" id="id_normal_message" style="display:none"><?php echo get_lang("PleaseStandBy")."<br/>".'<img src="/main/inc/lib/javascript/indicator.gif"/>'; ?></div>
 	<div class="confirmation-message" id="id_confirmation_message" style="display:none"></div>		
 	<div class="courseadminview">
 		<span class="viewcaption"><?php echo get_lang("Authoring") ?></span>

+ 19 - 36
main/course_home/course_home.php

@@ -67,9 +67,7 @@ $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jqu
 $htmlHeadXtra[] ='<script type="text/javascript">
  $(document).ready(function() {
  
- 	//$(window).load(function () { 
-      $(".make_visible_and_invisible").attr("href","javascript:void(0);");
-	//});
+    $(".make_visible_and_invisible").attr("href","javascript:void(0);");
 	cont=0;
  	$("td .make_visible_and_invisible > img").click(function () {
  		cont=cont+1;
@@ -82,25 +80,9 @@ $htmlHeadXtra[] ='<script type="text/javascript">
 		tool_id=$(this).attr("id");
 		tool_info=tool_id.split("_");
 		my_tool_id=tool_info[1];
-    
-       current_tool_image=$("#toolimage_"+my_tool_id).attr("src");
-	   list_current_tool_image=current_tool_image.split("/");
-	   image_for_replace=list_current_tool_image[list_current_tool_image.length-1];
-       list_new_image=image_for_replace.split(".");
-       		
-      if (image_for_replace.split("_na").length==2){
-			list_image_na=image_for_replace.split("_na");
-			list_image_na=list_image_na[0]+".gif";
-			new_current_tool_image=current_tool_image.replace(image_for_replace,list_image_na);
-			$("#tooldesc_"+my_tool_id).attr("class","");
-			$("#istooldesc_"+my_tool_id).attr("class","");					
-       } else {
-       	    new_image_to_replace=list_new_image[0]+"_na.gif";
-			new_current_tool_image=current_tool_image.replace(image_for_replace,new_image_to_replace);	
-			$("#tooldesc_"+my_tool_id).attr("class","invisible");
-			$("#istooldesc_"+my_tool_id).attr("class","invisible");		
-       	}
-		$("#toolimage_"+my_tool_id).attr("src",new_current_tool_image);
+		//Delete last item
+    	list_path_name[list_path_name.length-1]=null;
+    	real_path = list_path_name.join("/");
 
 		if (image_link=="visible.gif") {
 			mew_path_name=path_name.replace(make_visible,make_invisible);
@@ -113,7 +95,6 @@ $htmlHeadXtra[] ='<script type="text/javascript">
 		$.ajax({
 			contentType: "application/x-www-form-urlencoded",
 			beforeSend: function(objeto) {
-				$(".normal-message").append("<img src=\'/main/inc/lib/javascript/indicator.gif\'/>");
 				$(".normal-message").show();
 				$("#id_confirmation_message").hide();
 			},
@@ -121,9 +102,16 @@ $htmlHeadXtra[] ='<script type="text/javascript">
 			url: "/main/course_home/activity.php",
 			data: "id="+my_tool_id+"&visibility="+my_visibility+"&sent_http_request=1",
 			success: function(datos) {
-				
+				eval("var info="+datos);
+				new_current_tool_image = real_path+info.image;
+				//eyes
 				$("#"+tool_id).attr("src",mew_path_name);
-				
+				//tool
+				$("#toolimage_"+my_tool_id).attr("src",new_current_tool_image);
+				//clase
+				$("#tooldesc_"+my_tool_id).attr("class",info.class);
+				$("#istooldesc_"+my_tool_id).attr("class",info.class);
+
 				if (image_link=="visible.gif") {
 					$("#"+tool_id).attr("alt","'.get_lang('Activate').'");
 					$("#"+tool_id).attr("title","'.get_lang('Activate').'");
@@ -131,19 +119,14 @@ $htmlHeadXtra[] ='<script type="text/javascript">
 					$("#"+tool_id).attr("alt","'.get_lang('Deactivate').'");
 					$("#"+tool_id).attr("title","'.get_lang('Deactivate').'");							
 				}
-
-				if (datos=="ToolIsNowVisible") {
-					$("#id_confirmation_message").html("'.get_lang('ToolIsNowVisible').'");
-					$(".normal-message>img:first").remove();	
+				if (info.message=="is_active") {
+					message = "'.get_lang('ToolIsNowVisible').'";
 				} else {
-					$("#id_confirmation_message").html("'.get_lang('ToolIsNowHidden').'");
-					$("#id_confirmation_message").show();
-					$(".normal-message>img:first").remove();				
-				}
-				if ($(".normal-message>img:first").length==0) {
-					$(".normal-message").hide();
-					$("#id_confirmation_message").show();
+					message = "'.get_lang('ToolIsNowHidden').'";
 				}
+				$(".normal-message").hide();
+				$("#id_confirmation_message").html(message);
+				$("#id_confirmation_message").show();
 		} }); 		
 				
 	}); 	

+ 12 - 0
main/inc/lib/main_api.lib.php

@@ -3587,3 +3587,15 @@ function api_check_term_condition($user_id) {
 	}
 	return $return;
 }
+/**
+ * Get all information of the tool into course
+ * @param int The tool id
+ * @return array
+ */
+function api_get_tool_information ($tool_id) {
+   $t_tool = Database::get_course_table(TABLE_TOOL_LIST);	
+   $sql = 'SELECT * FROM '.$t_tool.' WHERE id="'.Database::escape_string($tool_id).'"';
+   $rs  = Database::query($sql,__FILE__,__LINE__);
+   $row = Database::fetch_array($rs);
+   return $row;
+}