Explorar el Código

Merge pull request #752 from visuddhinanda/laravel

🚑 资源分享给个人id为undefine

✨ 术语修改增加另存为功能

🐛 新建术语owner应该用channel的owner

🐛 新建术语刷新后没有弹出气泡
visuddhinanda hace 4 años
padre
commit
02efb26e41

+ 1 - 1
public/app/share/share.js

@@ -174,7 +174,7 @@ function username_search(keyword, type) {
 					for (const iterator of result) {
 						html +=
 							"<li onclick=\"user_selected('" +
-							iterator.uid +
+							iterator.id +
 							"','" +
 							iterator.username +
 							"',0)\">" +

+ 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);

+ 18 - 9
public/app/term/term_post.php

@@ -24,9 +24,9 @@ if (isset($_COOKIE["userid"]) == false) {
 $respond = array("status" => 0, "message" => "");
 PDO_Connect( _FILE_DB_TERM_);
 
+$channelInfo = new Channal($redis);
 
-
-if ($_POST["id"] != "") {
+if ($_POST["id"] != "" && !isset($_POST['save_as'])) {
 	#更新
 	#先查询是否有权限
 	#是否这个术语的作者
@@ -38,7 +38,7 @@ if ($_POST["id"] != "") {
 		if($Fetch){
 			if($Fetch['owner']!=$_COOKIE["userid"]){
 				#不是这个术语的作者,查是否是channel的有编辑权限者	
-				$channelInfo = new Channal($redis);
+				
 				$channelPower = $channelInfo->getPower($Fetch['channal']);
 				if($channelPower<20){
 					$respond['status'] = 1;
@@ -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(),
@@ -112,11 +111,21 @@ if ($_POST["id"] != "") {
 		$stmt = $PDO->prepare($query);
 		$stmt->execute(array($_POST["word"],$_POST["language"],$_POST["tag"],$_COOKIE["userid"]));
 	}else{
+        #TODO 
 		$query = "SELECT id from "._TABLE_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($_POST["channal"]==""){
+        $owner_uid = $_COOKIE["user_uid"];
+    }else{
+        $channel = $channelInfo->getChannal($_POST["channal"]);
+        if($channelInfo){
+            $owner_uid = $channel["owner_uid"];
+        }else{
+            $owner_uid = $_COOKIE["user_uid"];
+        }
+    }
 	if ($stmt) {
 		$Fetch = $stmt->fetch(PDO::FETCH_ASSOC);
 		if($Fetch){
@@ -137,7 +146,7 @@ if ($_POST["id"] != "") {
         $_POST["channal"],
         $_POST["language"],
         $_POST["note"],
-        $_COOKIE["user_uid"],
+        $owner_uid,
         $_COOKIE["user_id"],
         mTime(),
         mTime()
@@ -170,8 +179,8 @@ if ($_POST["id"] != "") {
         $respond['message'] = $_POST["word"];
         $respond['data'] = [
             "id"=>$parm[0],
-            "guid"=>$parm[2],
-			"word"=>$parm[3],
+            "guid"=>$parm[1],
+			"word"=>$parm[2],
 			"word_en"=>$parm[3],
 			"meaning"=>$parm[4],
 			"other_meaning"=>$parm[5],