Browse Source

:sparkles: 术语修改增加另存为功能

visuddhinanda@gmail.com 4 years ago
parent
commit
1f7bd3731b
3 changed files with 138 additions and 39 deletions
  1. 135 35
      public/app/term/term_edit_dlg.js
  2. 1 1
      public/app/term/term_popup.js
  3. 2 3
      public/app/term/term_post.php

+ 135 - 35
public/app/term/term_edit_dlg.js

@@ -7,7 +7,8 @@ function term_edit_dlg_init(title = gLocal.gui.dict_terms) {
 		outerHeight: "80vh",
 		buttons: [
 			{
-				text: gLocal.gui.save,
+                id:"term_edit_dlg_save",
+				text: gLocal.gui.submit,
 				click: function () {
 					term_edit_dlg_save();
 					$(this).dialog("close");
@@ -22,7 +23,10 @@ function term_edit_dlg_init(title = gLocal.gui.dict_terms) {
 		],
 	});
 }
-function term_edit_dlg_open(id = "", word = "",channel="",lang="") {
+/*
+obj:调用此函数的按钮的handle
+*/
+function term_edit_dlg_open(id = "", word = "",channel="",lang="",obj=null) {
 	if (id == "") {
 		let newWord = new Object();
 		newWord.guid = "";
@@ -33,7 +37,7 @@ function term_edit_dlg_open(id = "", word = "",channel="",lang="") {
 		newWord.note = "";
 		newWord.language = lang;
 		newWord.channel = channel;
-		let html = term_edit_dlg_render(newWord);
+		let html = term_edit_dlg_render(newWord,obj);
 		$("#term_edit_dlg_content").html(html);
 		$("#term_edit_dlg").dialog("open");
 	} else {
@@ -44,7 +48,7 @@ function term_edit_dlg_open(id = "", word = "",channel="",lang="") {
 			},
 			function (data) {
 				let word = JSON.parse(data);
-				let html = term_edit_dlg_render(word);
+				let html = term_edit_dlg_render(word,obj);
 				$("#term_edit_dlg_content").html(html);
 				$("#term_edit_dlg").dialog("open");
 			}
@@ -52,11 +56,11 @@ function term_edit_dlg_open(id = "", word = "",channel="",lang="") {
 	}
 }
 
-function term_edit_dlg_render(word = "") {
-	if (word == "") {
+function term_edit_dlg_render(word = null,obj=null) {
+	if (word == null) {
 		word = new Object();
 		word.guid = "";
-		word.word = pali;
+		word.word = "";
 		word.meaning = "";
 		word.other_meaning = "";
 		word.tag = "";
@@ -67,12 +71,21 @@ function term_edit_dlg_render(word = "") {
 	output += "<input type='hidden' id='term_edit_form_id' name='id' value='" + word.guid + "'>";
 	output += "<fieldset>";
 	output += "<legend>" + gLocal.gui.spell + "</legend>";
-	output +=
-		"<input type='input' id='term_edit_form_word' name='word' value='" +
-		word.word +
-		"'placeholder=" +
-		gLocal.gui.required +
-		">";
+    if(word.guid === "" && word.word === ""){
+        //新建术语 而且词头为空 允许修改word 拼写
+            "<input type='input' id='term_edit_form_word' name='word' value='" +
+            word.word +
+            ">";  
+    }else{
+        output += "<div style='font-size:200%;font-weight:700;'>"+word.word+"</div>";
+        output +=
+            "<input type='hidden' id='term_edit_form_word' name='word' value='" +
+            word.word +
+            "'placeholder=" +
+            gLocal.gui.required +
+            ">";        
+    }
+
 	output += "</fieldset>";
 
 	output += "<fieldset>";
@@ -115,50 +128,129 @@ function term_edit_dlg_render(word = "") {
 		" >";
 	output += "</fieldset>";
 
+
+
 	output += "<fieldset>";
+	output += "<legend>" + gLocal.gui.encyclopedia + "</legend>";
+	output += "<textarea id='term_edit_form_note' name='note' placeholder=" + gLocal.gui.optional +	" style='height:5em;'>";
+	output += word.note ;
+	output += "</textarea>";
+	output += "</fieldset>";
+
+
+
+    output += "<fieldset>";
 	output += "<legend>" + gLocal.gui.channel + "</legend>";
 
-	let currChannel=null;
+	let currChannel=null;//当前单词的channel
 	if(typeof word.channel == "undefined" && typeof word.channal != "undefined"){
 		word.channel = word.channal;
 	}
 	for (const iterator of _my_channal) {
-		if(iterator.id==word.channel){
+		if(iterator.uid==word.channel){
 			currChannel = iterator;
 		}
 	}
+    //查询术语所在句子的channel
+    let sentChannel=null;
+    let sentChannelId=null;
+    if(obj){
+        let sentObj = find_sent_tran_div(obj);
+        if(sentObj){
+            sentChannelId = sentObj.attr('channel');
+            for (const iterator of _my_channal) {
+                if(iterator.uid==sentChannelId){
+                    sentChannel = iterator;
+                }
+	        }
+        }
+    }
+    let style='display:none;';
+    if(word.guid === ''){
+        //新建术语 可以修改channel
+        style = 'display:block;';
+    }else{
+        //修改术语 不能修改channel
+        output +="<div>当前:" ;
+        if(word.channel === ''){
+            output += "通用于<b>所有版本</b>";
+        }else{
+            output += "仅使用于版本<b>";
+            if(currChannel !== null){
+                //我有写权限
+                output += currChannel.name;
+            }else{
+                //我没有写权限 设置按钮为disable
+                output += word.channel;
+            }
+            output += "</b>";
+        }
+        output += "</div>";
+        output +="<div><input type='checkbox' name='save_as' onchange='term_save_as(this)' />另存为</div>";
+    }
 
+    output += "<div id='term_save_as_channel' style='"+style+"' >";
 	output += "<select id='term_edit_form_channal' name='channal'>";
-	if(currChannel !== null){
-		if(currChannel.owner == getCookie("user_uid")){
-			//是自己的
-			output += "<option value=''>通用于所有版本</option>";
-			
-		}
-		output += "<option value='"+currChannel.id+"'>仅用于"+currChannel.name+"</option>";
-	}else{
-		output += "<option value=''>通用于所有版本</option>";
-	}
-	/*
+    //TODO 句子channel 是我自己的才显示通用于所有版本
+    if(sentChannelId){
+        if(sentChannel && sentChannel.power==30){
+            output += "<option value=''>通用于我的所有版本</option>";
+        }
+    }else{
+        //术语不在句子里,也显示
+        output += "<option value=''>通用于我的所有版本</option>";
+    }
+    
+    
+    /*
+    按照当前的默认匹配逻辑,先匹配句子所在channel 里面的术语,没有才匹配通用的
+    所以如果此术语匹配到了channel 说明这个channel一定是这个句子的channel 
+    在这种情况下,如果没有在我的有写权限的channel列表中找到,这个句子channel一定是我没有写权限的。
+    */
+
+    //句子channel 我有写权限才显示仅用于此channel
+    let ignoreChannelId=null;
+    if(word.channel === ''){
+        if(sentChannel !== null){
+            output += "<option value='"+sentChannel.uid+"'>[本句版本]"+sentChannel.name+"</option>";
+            ignoreChannelId = sentChannel.uid;
+        }
+    }
+    if(word.guid==''){
+        //新建术语
+        for (const iterator of _my_channal) {
+            if(iterator.uid==word.channel){
+                //这句我有写权限
+                output += "<option value='"+word.channel+"'>[本句版本]"+iterator.name+"</option>";
+                ignoreChannelId = word.channel;
+            }
+        }
+    }
+
 	for (const iterator of _my_channal) {
-		if(word.channel=="" || (word.channel!="" && iterator.id==word.channel)){
-			output += "<option value='"+iterator.id+"'>仅用于"+iterator.name+"</option>";
+        if(currChannel && currChannel.uid==iterator.uid){
+            continue;
+        }
+        if(ignoreChannelId === iterator.uid){
+            continue;
+        }
+		if(word.channel=="" || (word.channel!="" && iterator.uid !== word.channel)){
+			output += "<option value='"+iterator.uid+"' onclick=\"set_term_dlg_channel_msg('此术语将仅仅用于这个版本')\">仅用于"+iterator.name+"</option>";
 		}
 	}
-	*/
+	
 	output += "</select>";
+    output += "<div class='msg' id='term_dlg_channel_msg'>只有选择<b>通用版本</b>或者<b>本句版本</b>才会应用到这个句子</div>";
+    output += "</div>";
 	output += "</fieldset>";
 
-	output += "<fieldset>";
-	output += "<legend>" + gLocal.gui.encyclopedia + "</legend>";
-	output += "<textarea id='term_edit_form_note' name='note' placeholder=" + gLocal.gui.optional +	">";
-	output += word.note ;
-	output += "</textarea>";
-	output += "</fieldset>";
 	output += "</form>";
 
 	return output;
 }
+function set_term_dlg_channel_msg(msg){
+    $("#term_dlg_channel_msg").text(msg);
+}
 function term_edit_dlg_save() {
 	$.ajax({
 		type: "POST", //方法类型
@@ -202,3 +294,11 @@ function term_edit_dlg_save() {
 		},
 	});
 }
+
+function term_save_as(obj){
+    if(obj.checked){
+        $("#term_save_as_channel").show();
+    }else{
+        $("#term_save_as_channel").hide();
+    }
+}

+ 1 - 1
public/app/term/term_popup.js

@@ -65,7 +65,7 @@ function note_lookup_guid_json(guid) {
           html +=
             "<button onclick=\"term_edit_dlg_open('" +
             result.guid +
-            "')\">修改</button>";
+            "','','','',this)\">修改</button>";
           html += "</div>";
           html += "</div>";
           $("[term-popup='" + guid + "']").html(html);

+ 2 - 3
public/app/term/term_post.php

@@ -26,7 +26,7 @@ PDO_Connect( _FILE_DB_TERM_);
 
 
 
-if ($_POST["id"] != "") {
+if ($_POST["id"] != "" && !isset($_POST['save_as'])) {
 	#更新
 	#先查询是否有权限
 	#是否这个术语的作者
@@ -56,12 +56,11 @@ if ($_POST["id"] != "") {
 			exit;				
 		}
 	}
-    $query = "UPDATE "._TABLE_TERM_." SET meaning= ? ,other_meaning = ? , tag= ? ,channal = ? ,  language = ? , note = ? ,  modify_time= ? , updated_at = now()  where guid= ? ";
+    $query = "UPDATE "._TABLE_TERM_." SET meaning= ? ,other_meaning = ? , tag= ? ,  language = ? , note = ? ,  modify_time= ? , updated_at = now()  where guid= ? ";
 	$stmt = @PDO_Execute($query, 
 						array($_POST["mean"],
         					  $_POST["mean2"],
         					  $_POST["tag"],
-        					  $_POST["channal"],
         					  $_POST["language"],
         					  $_POST["note"],
         					  mTime(),