Mercurial > hg > extraction-interface
changeset 17:82f8c6bd2b69
add new tag will based on the current topic_id, insert new element into (1)taglist table and (2)topic_tag_relation table
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Fri, 20 Feb 2015 17:57:02 +0100 |
parents | fb948097de39 |
children | 115dda3d1728 |
files | develop/controllers/extractapp.php develop/js/taggingtext.js develop/models/extractapp.php develop/views/Extractapp/edittaglist.php develop/views/Extractapp/taggingtext.php |
diffstat | 5 files changed, 102 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/develop/controllers/extractapp.php Fri Feb 20 16:39:08 2015 +0100 +++ b/develop/controllers/extractapp.php Fri Feb 20 17:57:02 2015 +0100 @@ -118,7 +118,7 @@ $this->ReturnView($viewmodel->DeleteTag($this->postdata), true); break; default: // EditTaglist - $this->ReturnView($viewmodel->EditTaglist(), true); + $this->ReturnView($viewmodel->EditTaglist($this->postdata), true); break; } }
--- a/develop/js/taggingtext.js Fri Feb 20 16:39:08 2015 +0100 +++ b/develop/js/taggingtext.js Fri Feb 20 17:57:02 2015 +0100 @@ -254,10 +254,15 @@ url : './'+section_id, async : false, type : 'POST', - data : 'func=SaveFullText'+'&text='+encodeURIComponent(el.innerHTML)+'&filename='+section_id + data : 'func=SaveFullText'+'&text='+encodeURIComponent(el.innerHTML)+'&filename='+section_id, // data : 'func=SaveFullText'+'&text='+el.innerHTML+'&filename='+section_id + success: function (e) { + alert("Saved!"); + }, + error: function (e) { + alert("Haven't saved!"); + } }).done(function(result) { - alert("Saved!"); }); @@ -622,7 +627,7 @@ url : './TaggingText', async : false, data : 'func=SmartRegexSave'+'&text='+encodeURIComponent($('#smartRegexShowDiv').html())+'&filename='+name, - error: function (result) { + error: function (e) { alert("Error when saving"); } }).done(function(result) { @@ -830,25 +835,38 @@ var el = document.getElementById("listNameText"); $.ajax({ //url : '../../models/_extractapp_func.php', - url : './', + url : './Editwordlist', async : false, type : 'POST', - data : 'func=AddNewList'+'&text='+el.value + data : 'func=AddNewList'+'&text='+el.value, + success: function (e) { + alert("Added!"); + document.location.reload(true); + }, + error: function (e) { + console.log("error when add new list"); + alert("Haven't added new list!!"); + } }).done(function(result) { - alert("Added!"); - document.location.reload(true); + }); } function saveWordlist(id ) { var el = document.getElementById("editable-area"); $.ajax({ - url : './', + url : './Editwordlist', async : false, type : 'POST', - data : 'func=SaveWordlist'+'&text='+el.innerHTML+'&filename='+id + data : 'func=SaveWordlist'+'&text='+el.innerHTML+'&filename='+id, + success: function (e) { + alert("Saved!"); + }, + error: function (e) { + alert("Haven't saved!"); + } }).done(function(result) { - alert("Saved!"); + }); } @@ -902,7 +920,24 @@ // ============ // === for edittaglist.php === - +function editTaglist(topic_id) { + var form = document.createElement("form"); + form.setAttribute("method", "post"); + form.setAttribute("action", "./EditTaglist"); + form.setAttribute("target", "_blank"); + + var hiddenField = document.createElement("input"); + hiddenField.setAttribute("name", "topic_id"); + hiddenField.setAttribute("value", topic_id); + form.appendChild(hiddenField); + + if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1) { + document.body.appendChild(form); + form.submit(); + } else { + form.submit(); // works under IE and Chrome, but not FF + } +} // ============
--- a/develop/models/extractapp.php Fri Feb 20 16:39:08 2015 +0100 +++ b/develop/models/extractapp.php Fri Feb 20 17:57:02 2015 +0100 @@ -475,16 +475,29 @@ } // === for manage tag list === - public function EditTaglist() { - // $this->Initialize($urlvalues); - $result = $this->GetTaglist(); + public function EditTaglist($_postdata) { + + $topic_id = $_postdata['topic_id']; + $result = $this->GetTaglistByTopicID($topic_id); + + $taglistArray = array(); + foreach ($result as $row) { + $taglistArray[$row[0]] = array($row[1], $row[2], $row[3]); + //$taglistArray[$row['id']] = array($row['name'], $row['tag'], $row['color']); + // TODO: the format is not good, so I use $row[0], $row[1],... This could be changed some time. + } + + /* + //$result = $this->GetTaglist(); $taglistArray = array(); while ($row = mysql_fetch_assoc($result)) { $taglistArray[$row['id']] = array($row['name'], $row['tag'], $row['color']); } + */ $data = array(); $data['taglistArray'] = $taglistArray; + $data['topic_id'] = $topic_id; return $data; } @@ -515,6 +528,17 @@ $this->GetSQLValueString($color, "text"), $this->GetSQLValueString($this->systemNAME, "text")); $result1 = mysql_query($query1); + + + // add it to topic_tag_relation table + $topic_id = $postdata['topic_id']; + + // tag_id is $id; + $query = sprintf("INSERT INTO `topic_tag_relation` (`topic_id`,`tag_id`) VALUES (%s,%s)", $topic_id, $id); + $result = mysql_query($query); + if (!$result) { + echo json_encode("error when insert into topic_tag_relation table"); + } } }
--- a/develop/views/Extractapp/edittaglist.php Fri Feb 20 16:39:08 2015 +0100 +++ b/develop/views/Extractapp/edittaglist.php Fri Feb 20 17:57:02 2015 +0100 @@ -1,6 +1,7 @@ <?php // --- initialize --- $taglistArray = $viewmodel['taglistArray']; +$topic_id = $viewmodel['topic_id']; ?> @@ -203,18 +204,26 @@ } function newTag( id ) { + + var elid = document.getElementById("tdId"+id).textContent; + var elname = document.getElementById("tdName"+id).textContent; + var eltag = document.getElementById("tdTag"+id).textContent; + /* var elid = document.getElementById("tdId"+id).innerHTML; var elname = document.getElementById("tdName"+id).innerHTML; var eltag = document.getElementById("tdTag"+id).innerHTML; + */ var elcolor = $("#colorSelectorB"+id).css("background-color"); - console.log("elid="+elid+', elname='+elname); + console.log("elid="+elid+', elname='+elname+', eltag='+eltag); + var topic_id = JSON.parse('<?php echo json_encode($topic_id) ?>'); + $.ajax({ url : './EditTaglist', async : false, type : 'POST', - data : 'func=NewTagElement'+'&id='+elid+'&name='+elname+'&tag='+eltag+'&color='+elcolor, + data : 'func=NewTagElement'+'&id='+elid+'&name='+elname+'&tag='+eltag+'&color='+elcolor+'&topic_id='+topic_id, error: function (e) { console.log("error when newTag"); }, @@ -229,18 +238,27 @@ } function saveTag( id) { + + var elid = document.getElementById("tdId"+id).textContent; + var elname = document.getElementById("tdName"+id).textContent; + var eltag = document.getElementById("tdTag"+id).textContent; + /* var elid = document.getElementById("tdId"+id).innerHTML; var elname = document.getElementById("tdName"+id).innerHTML; var eltag = document.getElementById("tdTag"+id).innerHTML; + */ + var elcolor = $("#colorSelectorB"+id).css("background-color"); console.log(elid+','+elname+','+eltag+','+elcolor); + var topic_id = JSON.parse('<?php echo json_encode($topic_id) ?>'); + $.ajax({ url : './EditTaglist', async : false, type : 'POST', - data : 'func=SaveTagElement'+'&id='+elid+'&name='+elname+'&tag='+eltag+'&color='+elcolor, + data : 'func=SaveTagElement'+'&id='+elid+'&name='+elname+'&tag='+eltag+'&color='+elcolor+'&topic_id='+topic_id, error: function (e) { console.log("error when saving Tag"); }, @@ -270,7 +288,8 @@ if ( $("#input"+this.id).length > 0 ) { return; } - var startPageValue = this.innerHTML; + //var startPageValue = this.innerHTML; + var startPageValue = this.textContent; this.innerHTML=""; var newTextBox = document.createElement("input"); newTextBox.id = "input"+this.id; @@ -286,7 +305,8 @@ if ( $("#input"+this.id).length > 0 ) { return; } - var startPageValue = this.innerHTML; + //var startPageValue = this.innerHTML; + var startPageValue = this.textContent; this.innerHTML=""; var newTextBox = document.createElement("input"); newTextBox.id = "input"+this.id;
--- a/develop/views/Extractapp/taggingtext.php Fri Feb 20 16:39:08 2015 +0100 +++ b/develop/views/Extractapp/taggingtext.php Fri Feb 20 17:57:02 2015 +0100 @@ -562,7 +562,10 @@ <button onclick="editText()" id="editTextId" style="height: 30px; width: 220px">Edit the text</button></br> </br> <button onclick="window.open('./EditWordlist')" style="height: 30px; width: 220px">Manage Word List</button></br> + <!-- <button onclick="window.open('./EditTaglist')" style="height: 30px; width: 220px">Manage Tag List</button></br> + --> + <button onclick="editTaglist(<?php echo $default_topic_id; ?>)" style="height: 30px; width: 220px">Manage Tag List</button></br> </fieldset> <fieldset>