view views/Extractapp/ConfigTagsInTopic.php @ 77:97c1e5102a22 extractapp

New: export table for a file from LGService
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Thu, 16 Apr 2015 14:53:22 +0200
parents f9ae94a9b041
children f1f849d31272
line wrap: on
line source

<?php
/*! \file 
* This is a view for ConfigTagsInTopic.
* It shows tags in the current topic, and the other tags that are in our database but not in this topic.
* User can add/remove the tags in/out of this topic.
*/

// --- initialize ---
//$taglistArray = $viewmodel['taglistArray'];
$topic = $viewmodel['topic'];
$topic_name = $viewmodel['topic_name']; // array of names
$tag_intopic = $viewmodel['tag_intopic'];
$tag_others = $viewmodel['tag_others'];

?>

<html>
<head>
<title></title>
</head>

<body>
<script type="text/javascript">
function SelectMoveRows(s1, s2)
{
    var selId = '';
    var selText = '';
    // Move rows from s1 to s2 from bottom to top
    for (i = s1.options.length - 1; i >= 0; i--)
    {
        if (s1.options[i].selected == true)
        {
            selId = s1.options[i].value;
            selText = s1.options[i].text;
            var newRow = new Option(selText,selId);
            s2.options[s2.length] = newRow;
            s1.options[i] = null;
        }
    }
    SelectSort(s2);
}
function SelectSort(selList)
{
    var id = '';
    var t = '';
    for (x = 0; x < selList.length - 1; x++)
    {
        for (y = x+1; y < selList.length; y++)
        {
            if (selList[x].text > selList[y].text)
            {
                // Swap rows
                id = selList[x].value;
                t = selList[x].text;
                selList[x].value = selList[y].value;
                selList[x].text = selList[y].text;
                selList[y].value = id;
                selList[y].text = t;
            }
        }
    }
}

function checkTopic(t) {
	var ids = [];

	for (var i = 0; i < t.options.length; i++) {
		ids.push(t.options[i].value);
		console.log(t.options[i].text);
	}

	console.log(ids);
	var ids_json = JSON.stringify(ids);
	var topic_id = JSON.parse('<?php echo json_encode($topic) ?>');

	$.ajax({
		url : './ConfigTagsInTopic',
		async : false,
		type : 'POST',
		data : 'func=Update'+'&ids='+ids_json+'&topic_id='+topic_id,
		error: function (e) {
			console.log("error when update tags in topic"+ e );
		},
		success: function (e) {
			alert("Updated!");
		}
	}).done(function(result) {
	});

}

</script>

<div class="container-fluid" style="margin-left:10%; margin-right:10%">
		<form name="config" autocomplete='off' action="Javascript:checkTopic(document.config.InTopic)">
			<h3>Topic: <?php echo $topic_name['name_en'];?> (<?php echo $topic_name['name_ch'];?>, <?php echo $topic_name['name_pinyin'];?>) </h3>
			
			<table class="table">
				<thead>
					<tr>
						<td class="text-warning"> Selected tags </td>
						<td></td>
						<td class="text-warning"> Other tags </td>
					</tr>
				</thead>
				<tbody>
				<tr>
					<td>
						<select name="InTopic" size="<?php echo (count($tag_others)+count($tag_intopic))*0.8; ?>" class="form-control" multiple>
							<?php 
								foreach ($tag_intopic as $taglistValue) {
									echo "<option value='".$taglistValue['id']."'>".$taglistValue['name']." (".$taglistValue['tag'].") "."</option>";
								}
							?>
						</select>
					</td>
					<td align="center" valign="middle">
			            <input type="button" value="<< Add" class="btn btn-primary" onClick="SelectMoveRows(document.config.Others, document.config.InTopic)"><br>
			         	<br>
			            <input type="button" value="Remove >>" class="btn btn-warning" onClick="SelectMoveRows(document.config.InTopic, document.config.Others)"><br>
			        </td>
					<td >
						<select name="Others" size="<?php echo (count($tag_others)+count($tag_intopic))*0.8; ?>" class="form-control" multiple>
							<?php 
								foreach ($tag_others as $taglistValue) {
									echo "<option value='".$taglistValue['id']."'>".$taglistValue['name']." (".$taglistValue['tag'].") "."</option>";
								}
							?>
						</select>
					</td>
				</tr>
				<tr>
					<td></td>
					<td><input type="submit" value="Submit" class="btn btn-lg btn-success"></td>
					<td></td>
				</tr>
				</tbody>
			</table>
		</form>
</div>

</body>
</html>