# HG changeset patch # User Zoe Hong # Date 1447247575 -3600 # Node ID 9a29e9d28ece703e089ffc3da3d28f11e81364a8 # Parent b0cecc1046397c957a596ddc972cf3ff2fa6424d new: create new topic diff -r b0cecc104639 -r 9a29e9d28ece controllers/extractapp.php --- a/controllers/extractapp.php Mon Nov 09 12:00:24 2015 +0100 +++ b/controllers/extractapp.php Wed Nov 11 14:12:55 2015 +0100 @@ -101,13 +101,28 @@ case 'ContinueTagging': $viewmodel->messages['info'] .= "(Countinue tagging) "; - if ($this->postdata['topic']) { - $viewmodel->SetTopic($this->postdata['topic']); - } - $viewmodel->SetInfoFromPreviousPage($this->postdata); + $viewmodel->SetInfoFromPreviousPage($this->postdata); + $viewmodel->SetTextFromFileId(); // get text by fileId, from LGService + $viewmodel->SetTopic($this->postdata['topic']); + $this->ReturnView($viewmodel->StartTagging(), true); break; + case 'CreateNewTopic': + $result = $viewmodel->CreateNewTopic($this->postdata); + if ($result == "error") { + $viewmodel->messages['error'] .= "Fail to create the new topic
"; + } else { + // then act like ContinueTagging + $viewmodel->messages['info'] .= "Created a new topic
"; + $viewmodel->SetInfoFromPreviousPage($result); + $viewmodel->SetTextFromFileId(); // get text by fileId, from LGService + $viewmodel->SetTopic($result['topic']); + + } + $this->ReturnView($viewmodel->StartTagging(), true); + + break; default: // This is where the first time user visit extraction interface from LGService @@ -280,13 +295,20 @@ case 'Update': $viewmodel->UpdateTagsInTopic($this->postdata); break; + /* case 'CreateNewTopic': - $this->ReturnView($viewmodel->CreateNewTopic($this->postdata), true); + $result = $viewmodel->CreateNewTopic($this->postdata); + if ($result == "error") { + echo "Fail to create the new topic. Please contact us."; + } else { + $this->ReturnView($viewmodel->ConfigTagsInTopic($result), true); + } break; + */ default: $this->ReturnView($viewmodel->ConfigTagsInTopic($this->postdata), true); break; - } + } } diff -r b0cecc104639 -r 9a29e9d28ece css/taggingtext.css --- a/css/taggingtext.css Mon Nov 09 12:00:24 2015 +0100 +++ b/css/taggingtext.css Wed Nov 11 14:12:55 2015 +0100 @@ -114,8 +114,8 @@ z-index: 2; } .popup-newtopic { - left: -340px; - width: 340px; + left: -360px; + width: 360px; height: 340px; top: 100px; z-index: 2; diff -r b0cecc104639 -r 9a29e9d28ece js/taggingtext.js --- a/js/taggingtext.js Mon Nov 09 12:00:24 2015 +0100 +++ b/js/taggingtext.js Wed Nov 11 14:12:55 2015 +0100 @@ -29,7 +29,7 @@ var regex_element_index = 0; window.onbeforeunload = function() { - return "Are you sure?"; + return "Unsaved data will be lost."; }; @@ -558,11 +558,22 @@ replaceSmartClose(); } +$(document).keyup(function(e) { + if (e.keyCode == 27) { // escape key maps to keycode `27` + // close popups + $('#load_topic_div').css("display", "none"); + $('#new_topic_div').css("display", "none"); + $('#load_regex_div').css("display", "none"); + $('#regex_generator').css("display", "none"); + $('#smartRegexPopUpDiv').css("display", "none"); + $('.questionMarkClass').css("display", "none"); + $('.tagItemDivClass').css("display", "none"); + } +}); + $(document).on("click", '#smartRegexShowDiv > span', function (e) { - - $('#smartRegexPopUpDiv').css("display", "block"); $('#smartRegexPopUpDiv').attr("editID", $(this).attr("id")); diff -r b0cecc104639 -r 9a29e9d28ece models/extractapp.php --- a/models/extractapp.php Mon Nov 09 12:00:24 2015 +0100 +++ b/models/extractapp.php Wed Nov 11 14:12:55 2015 +0100 @@ -188,9 +188,10 @@ if (isset($_postdata['userId'])) { $this->user_id = $_postdata['userId']; } - if (isset($_postdata['topic_id'])) { - $this->topic = $_postdata['topic_id']; + if (isset($_postdata['topic'])) { + $this->topic = $_postdata['topic']; } + if (isset($_postdata['sectionName'])) { $this->section_name = $_postdata['sectionName']; } @@ -954,12 +955,87 @@ } // === for config topic === - public function ConfigTagsInTopic($postdata) { + public function CreateNewTopic($_postdata) { + $new_topic_id = "2"; // default topic_id=1 for 'person' topic + + // get user input data from postdata + $new_topic_name_en = $_postdata['new_topic_name_en']; + $new_topic_name_ch = $_postdata['new_topic_name_ch']; + $new_topic_name_pi = $_postdata['new_topic_name_pi']; + $new_topic_tag = $_postdata['new_topic_tag']; + $new_topic_tag_name = $_postdata['new_topic_tag_name']; + + // -- Start Transaction -- + mysql_query("BEGIN"); + + // create records for the new topic in database + /* In table: + taglist: name, tag, color (default, user can change later in the editing page) + topics: tag, name_en, name_ch, name_pinyin + topic_tag_relation: topic_id (new), tag_id (new) + + - need transaction for the following actions: + taglist.name: topic_tag name in chinese + taglist.tag: topic_tag name in eng + topics.tag: (the same a taglist.tag) + topics.name_en: + topics.name_ch: + topics.name_pinyin: + + + topic_tag_relation.topic_id = new_topic_id + topic_tag_relation.tag_id = new_tag_id + which are the new record that just been created in the 'taglist' and 'topics' table + */ + + // new record in topics table + $query="INSERT INTO topics (tag, name_en, name_ch, name_pinyin) VALUES ('".$new_topic_tag."','".$new_topic_name_en."','".$new_topic_name_ch."','".$new_topic_name_pi."')"; + $result_topics=mysql_query($query); + if($result_topics){ + $new_topic_id = mysql_insert_id(); + } else { + //echo mysql_error(); + } + + // new record in taglist table + $query="INSERT INTO taglist (name, tag, color, systemName) VALUES ('".$new_topic_tag_name."','".$new_topic_tag."','rgb(255, 0, 174)','interface')"; + $result_taglist=mysql_query($query); + if($result_taglist){ + $new_tag_id = mysql_insert_id(); + } else { + //echo mysql_error(); + } + + // new record in topic_tag_relation + $query="INSERT INTO topic_tag_relation (topic_id, tag_id) VALUES ('".$new_topic_id."','".$new_tag_id."')"; + $result_topic_tag_relation=mysql_query($query); + if($result_topic_tag_relation){ + + } else { + //echo mysql_error(); + } + + + // --- End Transaction --- + if ($result_taglist && $result_topics && $result_topic_tag_relation) { + mysql_query("COMMIT"); + + } else { + mysql_query("ROLLBACK"); + return "error"; + } + + + $_postdata['topic'] = $new_topic_id; + return $_postdata; + } + + public function ConfigTagsInTopic($_postdata) { /** * */ - $topic = $postdata['topic']; + $topic = $_postdata['topic']; $result = $this->GetTopicById($topic); $row = mysql_fetch_assoc($result); $topic_name_en = $row['name_en']; @@ -1046,10 +1122,7 @@ return $data; } - public function CreateNewTopic($_postdata) { - - } public function UpdateTagsInTopic($_postdata) { $topic_id = $_postdata['topic_id']; diff -r b0cecc104639 -r 9a29e9d28ece views/Extractapp/ConfigTagsInTopic.php --- a/views/Extractapp/ConfigTagsInTopic.php Mon Nov 09 12:00:24 2015 +0100 +++ b/views/Extractapp/ConfigTagsInTopic.php Wed Nov 11 14:12:55 2015 +0100 @@ -149,12 +149,17 @@ - + + + + diff -r b0cecc104639 -r 9a29e9d28ece views/Extractapp/EditTaglist.php --- a/views/Extractapp/EditTaglist.php Mon Nov 09 12:00:24 2015 +0100 +++ b/views/Extractapp/EditTaglist.php Wed Nov 11 14:12:55 2015 +0100 @@ -212,7 +212,9 @@ newcolumn.setAttribute("width","50"); if ( color=="Color") { row.appendChild(newcolumn).innerHTML="Delete"; - } else { + } else if (id == topic_tag_id) { + row.appendChild(newcolumn).innerHTML="-"; + } else { row.appendChild(newcolumn).innerHTML=""; } diff -r b0cecc104639 -r 9a29e9d28ece views/Extractapp/TaggingText.php --- a/views/Extractapp/TaggingText.php Mon Nov 09 12:00:24 2015 +0100 +++ b/views/Extractapp/TaggingText.php Wed Nov 11 14:12:55 2015 +0100 @@ -690,7 +690,7 @@ form.appendChild(hiddenField); var hiddenField = document.createElement("input"); - hiddenField.setAttribute("name", "topic_id"); + hiddenField.setAttribute("name", "topic"); hiddenField.setAttribute("value", topic_id); form.appendChild(hiddenField); @@ -708,40 +708,26 @@ $('#new_topic_div').css("display", "block"); } - - - - // TODO input new topic - /* In table: - taglist: name, tag, color (default, user can change later in the editing page) - topics: tag, name_en, name_ch, name_pinyin - - need transaction for the following actions: - taglist.name: topic_tag name in chinese - taglist.tag: topic_tag name in eng - topics.tag: (the same a taglist.tag) - topics.name_en: - topics.name_ch: - topics.name_pinyin: - add a new record in topic_tag_relation: topic_id, tag_id - */ - - - var newtopic = document.getElementById("newTopicSubmit"); newtopic.onclick = function(){ + // check if all fields are filled in + if ($("#newTopicNameEn").val()==""|| $("#newTopicNameCh").val()=="" || $("#newTopicNamePi").val()=="" || + $("#newTopicTag").val()=="" || $("#newTopicTagName").val()=="") { + alert("Please fill in all the fields for the new topic."); + return; + } + + var form = document.createElement("form"); form.setAttribute("method", "post"); - form.setAttribute("action", "./ConfigTagsInTopic"); // hand to controller - form.setAttribute("target", "_self"); // TODO self here? + form.setAttribute("action", "./TaggingText"); // hand to controller + form.setAttribute("target", "_self"); - // TODO var hiddenField = document.createElement("input"); hiddenField.setAttribute("name", "func"); hiddenField.setAttribute("value", "CreateNewTopic"); form.appendChild(hiddenField); - var hiddenField = document.createElement("input"); hiddenField.setAttribute("name", "new_topic_name_en"); @@ -764,7 +750,6 @@ hiddenField.setAttribute("value", $("#newTopicTagName").val()); form.appendChild(hiddenField); - _postForContineTagging(form); @@ -845,6 +830,7 @@ } + function _postForContineTagging(form) { var hiddenField = document.createElement("input"); hiddenField.setAttribute("name", "text"); @@ -856,6 +842,10 @@ // pass taglist var hiddenField = document.createElement("input"); hiddenField.setAttribute("name", "taglistArray"); + + // use json_encode($taglistArray), which is the up-to-date taglist (in db) instead, + // so replace the follwoing code + /* var taglistObj = JSON.parse(''); // if taglist_infile == "" means the taglist in db is up-to-date, will use taglistArray to save to file @@ -864,6 +854,10 @@ taglistObj = JSON.parse(''); } taglistArray = JSON.stringify(taglistObj); + */ + + + var taglistArray = JSON.parse(''); hiddenField.setAttribute("value", taglistArray); form.appendChild(hiddenField); @@ -1018,43 +1012,43 @@

New topic name:

- -
- + +
+
- -
- + +
+
- -
- + +
+
-

New topic tag:

+

Define the topic tag for the new topic:

- -
- + +
+
- -
- + +
+
-
+
@@ -1119,7 +1113,7 @@
Current topic is: (, ) - +