Browse Source

术语点击红色链接新建

visuddhinanda 5 years ago
parent
commit
8a98e30022
3 changed files with 64 additions and 17 deletions
  1. 15 11
      app/term/term.js
  2. 19 3
      app/term/term_edit_dlg.js
  3. 30 3
      app/term/term_post.php

+ 15 - 11
app/term/term.js

@@ -670,17 +670,21 @@ function term_updata_translation() {
 
 function term_show_win(guid, keyWord = "") {
 	if (guid == "") {
-		$(term_body).html(
-			"“" +
-				keyWord +
-				"”" +
-				gLocal.gui.no_created +
-				"<br /><button onclick=\"term_add_new('" +
-				keyWord +
-				"')\">" +
-				gLocal.gui.create_now +
-				"</button>"
-		);
+		if (typeof term_body == "undefined") {
+			term_edit_dlg_open("", keyWord);
+		} else {
+			$(term_body).html(
+				"“" +
+					keyWord +
+					"”" +
+					gLocal.gui.no_created +
+					"<br /><button onclick=\"term_add_new('" +
+					keyWord +
+					"')\">" +
+					gLocal.gui.create_now +
+					"</button>"
+			);
+		}
 	} else {
 		let currWord = term_lookup_my_id(guid);
 		if (currWord) {

+ 19 - 3
app/term/term_edit_dlg.js

@@ -21,8 +21,19 @@ function term_edit_dlg_init(title = gLocal.gui.dict_terms) {
 		],
 	});
 }
-function term_edit_dlg_open(id = "") {
+function term_edit_dlg_open(id = "", word = "") {
 	if (id == "") {
+		let newWord = new Object();
+		newWord.guid = "";
+		newWord.word = word;
+		newWord.meaning = "";
+		newWord.other_meaning = "";
+		newWord.tag = "";
+		newWord.note = "";
+		newWord.language = "zh";
+		newWord.channal = "";
+		let html = term_edit_dlg_render(newWord);
+		$("#term_edit_dlg_content").html(html);
 		$("#term_edit_dlg").dialog("open");
 	} else {
 		$.post(
@@ -43,7 +54,12 @@ function term_edit_dlg_open(id = "") {
 function term_edit_dlg_render(word = "") {
 	if (word == "") {
 		word = new Object();
-		word.pali = "";
+		word.guid = "";
+		word.word = pali;
+		word.meaning = "";
+		word.other_meaning = "";
+		word.tag = "";
+		word.note = "";
 	}
 	let output = "";
 	output += "<form action='##' id='form_term'>";
@@ -71,7 +87,7 @@ function term_edit_dlg_render(word = "") {
 	output += "<fieldset>";
 	output += "<legend>" + gLocal.gui.other_meaning + "</legend>";
 	output +=
-		"<input type='input' id='term_edit_form_othermeaning name='mean2' value='" +
+		"<input type='input' id='term_edit_form_othermeaning' name='mean2' value='" +
 		word.other_meaning +
 		"' placeholder=" +
 		gLocal.gui.optional +

+ 30 - 3
app/term/term_post.php

@@ -7,6 +7,7 @@ $respond=array("status"=>0,"message"=>"");
 PDO_Connect("sqlite:"._FILE_DB_TERM_);
 
 if($_POST["id"]!=""){
+	#更新
     $query="UPDATE term SET meaning= ? ,other_meaning = ? , tag= ? ,channal = ? ,  language = ? , note = ? , receive_time= ?, modify_time= ?   where guid= ? ";
     $stmt = @PDO_Execute($query,array($_POST["mean"],
                                         $_POST["mean2"],
@@ -17,7 +18,7 @@ if($_POST["id"]!=""){
                                         mTime(),
                                         mTime(),
                                         $_POST["id"]
-                                                            ));
+                                        ));
     if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
         $error = PDO_ErrorInfo();
         $respond['status']=1;
@@ -26,10 +27,36 @@ if($_POST["id"]!=""){
     else{
         $respond['status']=0;
         $respond['message']=$_POST["word"];
-    }		
+    }
 }
 else{
-
+	#新建
+	$parm[]=UUID::v4();
+	$parm[]=$_POST["word"];
+	$parm[]=pali2english($_POST["word"]);
+	$parm[]=$_POST["mean"];
+	$parm[]=$_POST["mean2"];
+	$parm[]=$_POST["tag"];
+	$parm[]=$_POST["channal"];
+	$parm[]=$_POST["language"];
+	$parm[]=$_POST["note"];
+	$parm[]=$_COOKIE["userid"];
+	$parm[]=0;
+	$parm[]=mTime();
+	$parm[]=mTime();
+	$parm[]=mTime();
+	$query="INSERT INTO term (id, guid, word, word_en, meaning, other_meaning, tag, channal, language,note,owner,hit,create_time,modify_time,receive_time ) 
+	VALUES (NULL, ? , ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) "; 
+	$stmt = @PDO_Execute($query,$parm);
+    if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+        $error = PDO_ErrorInfo();
+        $respond['status']=1;
+        $respond['message']=$error[2].$query;
+    }
+    else{
+        $respond['status']=0;
+        $respond['message']=$_POST["word"];
+    }
 }