Pārlūkot izejas kodu

术语输入后立即更新页面术语

visuddhinanda 4 gadi atpakaļ
vecāks
revīzija
5eb09a2195
3 mainītis faili ar 82 papildinājumiem un 21 dzēšanām
  1. 14 6
      app/term/term.js
  2. 25 15
      app/term/term_edit_dlg.js
  3. 43 0
      app/term/term_post.php

+ 14 - 6
app/term/term.js

@@ -420,7 +420,12 @@ function term_updata_translation() {
 	}
 	$("term").each(function () {
 		let status = $(this).attr("status");
-		let termText = $(this).text();
+
+		let termText;
+		termText = $(this).attr("pali");
+		if(typeof termText=="undefined"){
+			termText = $(this).text();
+		}
 
 		if (termText.slice(0, 1) == "#") {
 			if (status == 0) {
@@ -432,7 +437,8 @@ function term_updata_translation() {
 			$(this).html("<a onclick=\"alert('" + noteText + "')\">[" + noteCounter + "]</a>");
 			noteCounter++;
 		} else {
-			if (status == 0 || status == 2) {
+			//if (status == 0 || status == 2) 
+			{
 				let myterm = term_lookup_my(
 					termText,
 					$(this).attr("channal"),
@@ -457,6 +463,8 @@ function term_updata_translation() {
 			let mean = $(this).attr("mean");
 			let mean2 = $(this).attr("mean2");
 			let renderTo = $(this).attr("pos");
+			let channel = $(this).attr("channal");
+			let lang = $(this).attr("lang");
 			let noteText = "";
 
 			if (termCounter[guid]) {
@@ -504,7 +512,7 @@ function term_updata_translation() {
 						guid +
 						"','" +
 						pali +
-						"')\">"
+						"','"+channel+"','"+lang+"')\">"
 				);
 				noteText = noteText.replace("]", "</span>");
 				noteText = noteText.replace("%mean%", "<span class='term_mean'>" + mean + "</span>");
@@ -535,7 +543,7 @@ function term_updata_translation() {
 					str_term_fun_word_link +
 					"('','" +
 					termText +
-					"')\">" +
+					"','"+channel+"','"+lang+"')\">" +
 					termText +
 					"</span>";
 			}
@@ -545,10 +553,10 @@ function term_updata_translation() {
 	term_popup_init();
 }
 
-function term_show_win(guid, keyWord = "") {
+function term_show_win(guid, keyWord = "",channel="",lang="") {
 	if (guid == "") {
 		if (typeof term_body == "undefined") {
-			term_edit_dlg_open("", keyWord);
+			term_edit_dlg_open("", keyWord,channel,lang);
 		} else {
 			$(term_body).html(
 				"“" +

+ 25 - 15
app/term/term_edit_dlg.js

@@ -22,7 +22,7 @@ function term_edit_dlg_init(title = gLocal.gui.dict_terms) {
 		],
 	});
 }
-function term_edit_dlg_open(id = "", word = "") {
+function term_edit_dlg_open(id = "", word = "",channel="",lang="") {
 	if (id == "") {
 		let newWord = new Object();
 		newWord.guid = "";
@@ -31,8 +31,8 @@ function term_edit_dlg_open(id = "", word = "") {
 		newWord.other_meaning = "";
 		newWord.tag = "";
 		newWord.note = "";
-		newWord.language = "zh";
-		newWord.channal = "";
+		newWord.language = lang;
+		newWord.channel = channel;
 		let html = term_edit_dlg_render(newWord);
 		$("#term_edit_dlg_content").html(html);
 		$("#term_edit_dlg").dialog("open");
@@ -117,22 +117,21 @@ function term_edit_dlg_render(word = "") {
 
 	output += "<fieldset>";
 	output += "<legend>" + gLocal.gui.channel + "</legend>";
-	output +=
-		"<input type='input' id='term_edit_form_channal' name='channal' value='" +
-		word.channal +
-		"' placeholder=" +
-		gLocal.gui.optional +
-		">";
+	output += "<select id='term_edit_form_channal' name='channal'>";
+	output += "<option value=''>通用于所有版本</option>";
+	for (const iterator of _my_channal) {
+		if(iterator.id==word.channel){
+		output += "<option value='"+iterator.id+"'>仅用于"+iterator.name+"</option>";
+		}
+	}
+	output += "</select>";
 	output += "</fieldset>";
 
 	output += "<fieldset>";
 	output += "<legend>" + gLocal.gui.encyclopedia + "</legend>";
-	output +=
-		"<textarea id='term_edit_form_note' name='note' placeholder=" +
-		gLocal.gui.optional +
-		">" +
-		word.note +
-		"</textarea>";
+	output += "<textarea id='term_edit_form_note' name='note' placeholder=" + gLocal.gui.optional +	">";
+	output += word.note ;
+	output += "</textarea>";
 	output += "</fieldset>";
 	output += "</form>";
 
@@ -149,6 +148,17 @@ function term_edit_dlg_save() {
 
 			if (result.status == 0) {
 				alert(result.message + gLocal.gui.saved + gLocal.gui.successful);
+				for (let index = 0; index < arrMyTerm.length; index++) {
+					const element = arrMyTerm[index];
+					if(element.guid==result.data.guid){
+						arrMyTerm.splice(index);
+						break;
+					}
+				}
+				arrMyTerm.push(result.data);
+				
+				term_updata_translation();
+
 			} else {
 				alert("error:" + result.message);
 			}

+ 43 - 0
app/term/term_post.php

@@ -58,6 +58,17 @@ if ($_POST["id"] != "") {
     } else {
         $respond['status'] = 0;
         $respond['message'] = $_POST["word"];
+        $respond['data'] = ["guid"=>$_POST["id"],
+							"word"=>$_POST["word"],
+							"word_en"=>$_POST["word"],
+							"meaning"=>$_POST["mean"],
+							"other_meaning"=>$_POST["mean2"],
+							"tag"=>$_POST["tag"],
+							"channal"=>$_POST["channal"],
+							"language"=>$_POST["language"],
+							"note"=>$_POST["note"],
+							"owner"=>$_COOKIE["userid"]
+						];
     }
 } else {
 	#新建
@@ -79,6 +90,26 @@ if ($_POST["id"] != "") {
 		echo json_encode($respond, JSON_UNESCAPED_UNICODE);
 		exit;
 	}
+	#先查询是否有重复数据
+	if($_POST["channal"]==""){
+		$query = "SELECT id from term where word= ? and  language=? and tag=? and owner = ? ";
+		$stmt = $PDO->prepare($query);
+		$stmt->execute(array($_POST["word"],$_POST["language"],$_POST["tag"],$_COOKIE["userid"]));
+	}else{
+		$query = "SELECT id from term where word= ? and channal=?  and tag=? and owner = ? ";
+		$stmt = $PDO->prepare($query);
+		$stmt->execute(array($_POST["word"],$_POST["channal"],$_POST["tag"],$_COOKIE["userid"]));
+	}
+	
+	if ($stmt) {
+		$Fetch = $stmt->fetch(PDO::FETCH_ASSOC);
+		if($Fetch){
+			$respond['status'] = 1;
+			$respond['message'] = "已经有同样的记录";
+			echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+			exit;
+		}
+	}
     $parm[] = UUID::v4();
     $parm[] = $_POST["word"];
     $parm[] = pali2english($_POST["word"]);
@@ -103,6 +134,18 @@ if ($_POST["id"] != "") {
     } else {
         $respond['status'] = 0;
         $respond['message'] = $_POST["word"];
+        $respond['data'] = ["guid"=>$parm[0],
+							"word"=>$parm[1],
+							"word_en"=>$parm[2],
+							"meaning"=>$parm[3],
+							"other_meaning"=>$parm[4],
+							"tag"=>$parm[5],
+							"channal"=>$parm[6],
+							"language"=>$parm[7],
+							"note"=>$parm[8],
+							"owner"=>$parm[9]
+						];
+
     }
 }