Button in polymer element not calling on-click function - dart

So I have some select elements and a button declared like this within a polymer-element
...
<tr>
<td>
<select name="taskTypes" selectedIndex="{{selectedTaskTypeFilter}}">
<option template repeat="{{key in taskTypeIndexes}}" value="{{key.toString()}}">
{{taskTypes[key]}}
</option>
</select>
</td>
<td>
<select name="taskStatusFilter" selectedIndex="{{selectedStatusFilter}}">
<option template repeat="{{key in statusFilterIndexes}}" value="{{key.toString()}}">
{{statusFilters[key]}}
</option>
</select>
</td>
<td>
<select name="targetLanguage" selectedIndex="{{selectedTargetFilter}}">
<option template repeat="{{language in activeTargetLanguages}}" value="{{language.code}}">
{{language.name}}
</option>
</select>
</td>
</tr>
<button value="Filter" class="btn btn-primary" on-click="{{filterStream}}">
<i class="icon-refresh icon-white"></i> {{localisation.getTranslation("index_filter_task_stream")}}
</button>
...
(Inb4 someone bemoans use of tables; it's not my code originally and I kind of would like to replace them but it's not top priority.)
This is the filterStream() function the button is supposed to call but it seems not to get called at all as is evident from the output of the print statement not showing up.
void filterStream()
{
print("Entered filterStream");
filter = "";
if (isFiltered) {
filteredTasks.clear();
filteredTasks.addAll(filteredTasksBackup);
}
if (filteredTasksBackup.length == 0) {
UserDao.getUserTasks(userid, taskCount)
.then((List<Task> userTasks) {
filteredTasks = userTasks;
filteredTasksBackup = userTasks;
isFiltered = true;
});
}
if (selectedTaskTypeFilter > 0) {
//Remove all tasks but those of the selected type
filteredTasks.removeWhere((task) => task.taskType != selectedTaskTypeFilter);
}
if (selectedStatusFilter > 0) {
//Remove all tasks but those with the selected status
//The + 2 is to adjust the values so that they match correctly; task status 3 and 4 are in progress and
//complete, respectively, but on the UI filter they are the 2nd and 3rd options (hence index 1 and 2).
filteredTasks.removeWhere((task) => task.taskStatus != selectedStatusFilter + 2);
}
goToFirstPage();
}
The full ClaimedTaskStream.dart file can be found here if it helps. Also, as it may be relevant, I should mention I am running the code as JS compiled by dart2js.

The method needs to have three arguments Event, detail, and target
filterStream(MouseEvent e, detail, Element target) { }

Related

ASP.NET MVC Filter Options in Select List (DataTable)

I created a filter section using DataTables API and it seems working fine, except for the Status column that has Select List Options.
The filter function is searching every option that contains in Select List, but I want it to search only the first option in Select List.
For example: when I input 'Manual', I need it to filter only the first row, not a second row that got options value 'Manual' in it.
Before filter:
After filter:
HTML Code (in DataTable)
#if (dealer.STATUS == "R" || dealer.STATUS == "M")
{
<td class="tdStaff" data-label="Status">
#if(#Model.SelectLists.Where(x => x.Value == dealer.STATUS).Select(x => x.Value).First() == "M")
{
<select name="statusname">
<option value="M">Manual Pay</option>
<option value="R">Reject</option>
</select>
}
else if (#Model.SelectLists.Where(x => x.Value == dealer.STATUS).Select(x => x.Value).First() == "R")
{
<select name="statusname">
<option value="R">Reject</option>
<option value="M">Manual Pay</option>
</select>
}
</td>
}
else
{
<td>#dealer.STATUS_NAME</td>
}
Filter Function
function addSearchControl(json) {
$("#myTable thead").append($("#myTable thead tr:first").clone());
$("#myTable thead tr:eq(1) th").each(function(index) {
$(this).replaceWith('<th><input type="text" placeholder="' + $(this).html() + '..." style="width:100%"></input></th>');
var searchControl = $("#myTable thead tr:eq(1) th:eq(" + index + ") input");
searchControl.on('keyup', function() {
dataTable.column(index).search(searchControl.val()).draw();
});
});
}
Expect this to filter value only the first option in Select List.
Hope you understand and any advice would be grateful, Thanks.

How do I correctly output glyphicon based on my int field?

How do I get glyphicon to appear based on int field in my razor page?
#foreach (var item in Model)
{
<tr>
<td>
<span class="glyphicon">
#item.Status == 0 ?  : 
</span>
</td>
Image shows incorrect output
This is a limitation of razor when trying to mix code blocks and content when the content is not wrapped in html tags
2 options you can use are
<span class="glyphicon">
#(item.Status == 0 ? #Html.Raw("") : #Html.Raw(""));
</span
or using razors #: syntax (which denotes that the line is treated as html content)
<span class="glyphicon">
#if(item.Status == 0) {
#:
} else {
#:
}
</span

Select2 trigger select all checkbox

I am using Select2 dropdown, my requirement is to check uncheck checkbox value. If all options are selected then checkbox checked and if all options are not selected then checkbox uncheck.
HTML
<select multiple id="e1" style="width:300px">
<option value="AL">Alabama</option>
<option value="Am">Amalapuram</option>
<option value="An">Anakapalli</option>
<option value="Ak">Akkayapalem</option>
<option value="WY">Wyoming</option>
</select>
<input type="checkbox" id="checkbox" >Select All
<input type="button" id="button" value="check Selected">
JS
$("#e1").select2();
$("#checkbox").click(function(){
if($("#checkbox").is(':checked') ){
$("#e1 > option").prop("selected","selected");
$("#e1").trigger("change");
}else{
$("#e1 > option").removeAttr("selected");
$("#e1").trigger("change");
}
});
$("#button").click(function(){
alert($("#e1").val());
});
Fiddle
http://jsfiddle.net/jEADR/62/.
You need to catch the change event, when event fire you need check how many options chosen and compare them with all of the options:
$("#e1").on("change", function(e) {
var count = this.selectedOptions.length // how options selected
var opt = this.length; // how options total
if (count===opt) {
// all selected
$("#checkbox").prop('checked', true);
} else {
// not all selected
$("#checkbox").prop('checked', false);
}
});
http://jsfiddle.net/jEADR/1834/

Ajax.BeginForm alternatives to onchange=this.form.submit()

I have a table with a Ajax.BeginForm on each row. This works good to pass the data to the controller.
However, it wont fire the Request.IsAjaxRequest() on the controller because of the form post(thanx HTX9 for pointing that out!). The real problem is that it returns a partial view instead of updating it in the current view.
Below you can see two fieldsets. The first is the one i want to update and the one below it is the one which sends data to the controller with the Ajax.BeginForm.
With other words: When I choose something in a dropdownlist it updates the table above but it opens it in a new partial view.
I have the unobtrusive ajax js in the _layout view and a similar setup works in an other part of the application from with a post data with a button instead.
<fieldset>
<legend>Direktbyten</legend>
<div id="container-grid2">
#Html.Partial("_RatingList2", Model.Models2)
</div>
</fieldset>
<fieldset>
<legend>Omarkerade byten(#ViewBag.DirectCount)</legend>
<div id="RatingList">
<table>
<thead>
<tr>
<td>Se hela</td>
<td>Hyra</td>
<td>Rum</td>
<td>Kvm</td>
<td>Gata</td>
<td>Område</td>
<td>Deras prio</td>
<td>Totaltvärde</td>
<td>Min prio</td>
</tr>
</thead>
<tbody>
#foreach (var item in Model.Models1)
{
using (Ajax.BeginForm("UpdateRatingListRow", new AjaxOptions { UpdateTargetId = "container-grid2" }))
{
#Html.Hidden("RatingListId", item.RatingListId)
<tr>
<td>#Html.ActionLink("Till annons", "ViewAd", "Ad", new { id = item.CustomerId }, null)
</td>
<td>#item.Rent</td>
<td>#item.Rooms</td>
<td>#item.SquareMeters</td>
<td>#item.Street</td>
<td>#item.Area</td>
<td>#item.TheirRating</td>
<td>#item.TotalRating</td>
<td>
#Html.Raw("<div id='" + item.RatingListId + "'>")
<select name="SelectedValue" onchange="this.form.submit();">
<option value="0"#if (item.MyRating == "00")
{
#Html.Raw("selected")
}>Ny</option>
<option value="10" #if (item.MyRating == "10")
{
#Html.Raw("selected")
}>Inget intresse</option>
<option value="50"#if (item.MyRating == "50")
{
#Html.Raw("selected")
}>Svagt intressse</option>
<option value="60"#if (item.MyRating == "60")
{
#Html.Raw("selected")
}>Litet intresse-vill ej ha kontakt</option>
<option value="70"#if (item.MyRating == "70")
{
#Html.Raw("selected")
}>Intresserad-Vill ha kontakt</option>
<option value="80"#if (item.MyRating == "80")
{
#Html.Raw("selected")
}>Varit på visning-Vill gå vidare</option>
<option value="90"#if (item.MyRating == "90")
{
#Html.Raw("selected")
}>Intresserad-Vill ha kontakt</option>
<option value="100"#if (item.MyRating == "100")
{
#Html.Raw("selected")
}>Avvaktar värdar</option>
</select>#item.MyRating
#Html.Raw("</div>")
</td>
</tr>
}
}
</tbody>
</table>
</div>
</fieldset>
Here is the Controller:
[HttpPost]
public ActionResult UpdateRatingListRow()
{
if (Request.IsAjaxRequest())
{
//Do stuff, it does not hit this part because of the isAjaxRequest().
return this.PartialView("_RatingList2", myRatingListMarked);
}
return this.PartialView("_RatingList2", null);
}
Generated Html:
Here is my "fulhack"(ugly hack in swedish), added a button with each row id and then i call it for submit. Still hoping for a clean solution without having to rewrite a lot of code.
using (Ajax.BeginForm("UpdateRatingListRow", new AjaxOptions { UpdateTargetId = "container-grid2", OnSuccess = "OnSuccess('" + item.RatingListId + "')" }))
{
<input type="submit" id="#item.RatingListId" style="position: absolute; top: -1000px">
#Html.Hidden("RatingListId", item.RatingListId)
<tr>
<td>#Html.ActionLink("Till annons", "ViewAd", "Ad", new { id = item.CustomerId }, null)</td>
<td>#item.Rent</td>
<td>#item.Rooms</td>
<td>#item.SquareMeters</td>
<td>#item.Street</td>
<td>#item.Area</td>
<td>#item.TheirRating</td>
<td>#item.TotalRating</td>
<td>#Html.Raw("<div id='" + item.RatingListId + "'>")
<select name="SelectedValue" onchange="document.getElementById(#item.RatingListId).click();">
<option value="0"#if (item.MyRating == "00")

jquery custom events attached to .show and .hide

I'm exploring the potential of jquery to satisfy some of our UI requirements, and am experiencing some curious behaviour. I'm very new to jQuery, and I'm trying to implement a basic pub-sub type of pattern that's hooked into the show & hide functions.
Despite the custom event mechanism looking perfectly simple on the surface, it isn't behaving as I expect. I can't see my syntactical mistake, so I must be misunderstanding the way these custom events are intended to work.
When I execute this code, Here's what I think should happen.
Initially (after doc.Ready) the question2 element should be hidden.
When I click on the 'Vermont' radio button, question 2 should be made visible followed by one alert box indicating that 'question2 has been made visible'.
When I click on another radio button, question 2 should be hidden followed by one alert box indicating that question 2 has been made hidden.
What is actually happening is that I get numerous alert boxes when making question 2 visible, and none when I hide it?
Please help me understand why it's doing this.
Here is the script:
<script type="text/javascript">
function processRadioButtonASD() {
var isChecked = ($("input[name=question1]:checked").val() == "question1.Vermont");
if (isChecked == true) {
$("[data-uniquename=question2]").show(250);
} else {
$("[data-uniquename=question2]").hide(250);
}
}
function detectVisibilityChange(uniqueName) {
$("[data-uniquename=" + uniqueName + "]").bind("madeVisible", function () {
alert($(this).attr("data-uniquename") + " was made visible");
});
$("[data-uniquename=" + uniqueName + "]").bind("madeHidden", function () {
alert($(this).attr("data-uniquename") + " was made hidden");
});
}
$(function () {
$.each(["show", "hide"], function () {
var _oldFn = $.fn[this];
$.fn[this] = function () {
var wasVisible = $(this).is(':visible');
var result = _oldFn.apply(this, arguments);
var isVisible = $(this).is(':visible');
if ((isVisible == true) && (wasVisible == false)) {
$(this).triggerHandler("madeVisible");
} else if ((isVisible == false) && (wasVisible == true)) {
$(this).triggerHandler("madeHidden");
}
return result;
}
});
});
$(document).ready(function () {
processRadioButtonASD();
detectVisibilityChange("question2");
$("input[name='question1']").change(function () { processRadioButtonASD(); });
});
</script>
Here is the html:
<div id="content">
<div id="radioButtonASD" class="example">
<h2>radio button visibility trigger</h2>
<div data-uniquename="question1" class="question">
<label for="question1">
Question 1) (select Vermont to show Question2)
</label>
<br />
<label data-uniquename="question1.Maine">
<input name="question1" data-uniquename="question1.Maine" type="radio" value="me" />Maine</label><br />
<label data-uniquename="question1.Vermont">
<input name="question1" data-uniquename="question1.Vermont" type="radio" value="question1.Vermont" />Vermont</label><br />
<label data-uniquename="question1.NewHampshire">
<input name="question1" data-uniquename="question1.NewHampshire" type="radio" value="question1.NewHampshire" />New
Hampshire</label><br />
<label data-uniquename="question1.Conneticut">
<input name="question1" data-uniquename="question1.Conneticut" type="radio" value="question1.Conneticut" />Conneticut</label><br />
<label data-uniquename="question1.Massachusetts">
<input name="question1" data-uniquename="question1.Massachusetts" type="radio" value="question1.Massachusetts" />Massachusetts
</label>
</div>
<br />
<div data-uniquename="question2" class="question">
<label>
Question 2)
</label>
<br />
<select>
<option data-uniquename="question2.honda" value="honda">Honda</option>
<option data-uniquename="question2.volvo" value="volvo">Volvo</option>
<option data-uniquename="question2.saab" value="saab">Saab</option>
<option data-uniquename="question2.mercedes" value="mercedes">Mercedes</option>
<option data-uniquename="question2.audi" value="audi">Audi</option>
</select>
</div>
</div>
</div>
Thanks for looking.
I came up with an alternative way.
$.each(["show", "hide"], function() {
var effect = $.fn[this];
$.fn[this] = function(duration, move, callback) {
// Match the arguments
var speed = duration;
var easing = callback && move || move && !jQuery.isFunction( move ) && move;
var fn = callback || !callback && move || jQuery.isFunction( duration ) && duration;
// Wrap the callback function
var wrapped = fn;
var wasVisible = $(this).is(':visible');
fn = function(){
var isVisible = $(this).is(':visible');
$.proxy(wrapped, this);
if ((isVisible == true) && (wasVisible == false)) {
$(this).triggerHandler("madeVisible");
} else if ((isVisible == false) && (wasVisible == true)) {
$(this).triggerHandler("madeHidden");
}
};
// Run the effect with the wrapped callback
return effect.call(this, speed, easing, fn);
};
});
The idea is make use of the callback function. From there you can refactor and clean the code.
Take a look at a working example.

Resources