sudo find . -type f -exec chmod 644 {} \;
sudo find . -type d -exec chmod 755 {} \;
Tuesday, March 15, 2016
Change [all files and folders] of a [directory] to 644 and 755
I came across a situation to run chmod 755 [folder] and chmod 644 [file] on my php dev folder. The following would handle all files and folders of current working folder.
Thursday, March 10, 2016
Use Bootstrap Popover to load external content through Ajax
It seemed easy to load an external contents through Ajax onto Bootstrap Popover at first. In fact, it wasn't as straightforward as I would like.
Using the content() function, it is straightforward to load any static content.
Using the content() function, it is straightforward to load any static content.
<a class="pop">Link</a>
<div id="contentDiv" style="display:none;">Some content...</div>
<script type="text/javascript">
$('.pop').popover({
html: true,
content: function(){
return $('#contentDiv').html();
}
});
</script>
However, loading an external content dynamically through Ajax plus "Loading ..." message took some thoughts.<a class="pop" href="Product/100">Link</a>
<script type="text/javascript">
$('.pop').popover({
html: true,
content: function(){
// Create a random temporary id for the content's parent div
// with a unique number just in case.
var content_id = "content-id-" + $.now();
$.ajax({
type: 'GET',
url: $(this).prop('href'),
cache: false,
}).done(function(d){
$('#' + content_id).html(d);
});
return '<div id="' + content_id + '">Loading...</div>';
// Initially, the content() function returns a parent div,
// which shows "Loading..." message.
// As soon as the ajax call is complete, the parent div inside
// the popover gets the ajax call's result.
}
});
</script>
Keeping the Bootstrap Popover alive while mouse moves from triggering element to the popover
I tried to use the Bootstrap Popover as a quick dynamic ajax form within which I can perform further actions. By default, when popover appears as a result of hovering over the triggering element, it disappears when the triggering element is no longer hovered.
One easy way to keep the popover stay put until I am no longer hovering over the triggering element or the popover itself is to use { trigger: "manual", html: true, animation: false } and handle the trigger via "mouseenter" and "mouseleave" event.
One easy way to keep the popover stay put until I am no longer hovering over the triggering element or the popover itself is to use { trigger: "manual", html: true, animation: false } and handle the trigger via "mouseenter" and "mouseleave" event.
// the triggering element has class of 'pop'
$(".pop").popover({
trigger: "manual",
html: true,
animation: false
}).on("mouseenter", function(){
var _this = this;
$(this).popover("show");
$(".popover").on("mouseleave", function(){
$(_this).popover('hide');
});
}).on("mouseleave", function(){
var _this = this;
setTimeout(function(){
if (!$(".popover:hover").length){
$(_this).popover("hide");
}
}, 50);
// If popover is not hovered within 50 milliseconds
// after the mouse leaves the triggering element,
// the popover will be hidden.
// 50 milliseconds seem fine in most cases.
});
Thursday, March 3, 2016
@Html.CheckBoxFor( ) helper method problem when posting to Controller method with Bind(Include=...) annotation
@Html.CheckBoxFor(model => model.IsDeposit) will generate html
The cause of this problem seems to be the IsDeposit in the Bind(Include=...) annotation is not handled properly yet in ASP.NET MVC. @Html.CheckBoxFor(..) creates two elements with the same name attribute (checkbox and hidden). Possibly only the hidden element is accepted to the method when Bind(Include=..) is used. I tried including "IsDeposit" twice (for example, Bind[Include=IsDeposit,IsDeposit,,]) just in case, but it did not help.
The best bet is to avoid using the Bind(Include=...) annotation when @Html.CheckBoxFor() helper method is used. Alternatively, you can also create the checkbox element manually yourself instead of using the helper method @Html.CheckBoxFor(). For example,
<input type="checkbox" name="IsDeposit" value="true" /> <input type="hidden" name="IsDeposit" value="false" />given that IsDeposit is a boolean value. Then the form is submitted to a method in controller such as
[HttpPost, ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include ="PaymentID,IsDeposit")] Payment payment)
{ . . . }
The problem is that the checkbox value will always be false whether the checkbox is checked or not.
The cause of this problem seems to be the IsDeposit in the Bind(Include=...) annotation is not handled properly yet in ASP.NET MVC. @Html.CheckBoxFor(..) creates two elements with the same name attribute (checkbox and hidden). Possibly only the hidden element is accepted to the method when Bind(Include=..) is used. I tried including "IsDeposit" twice (for example, Bind[Include=IsDeposit,IsDeposit,,]) just in case, but it did not help.
The best bet is to avoid using the Bind(Include=...) annotation when @Html.CheckBoxFor() helper method is used. Alternatively, you can also create the checkbox element manually yourself instead of using the helper method @Html.CheckBoxFor(). For example,
<input type="checkbox" name="IsDeposit" id="IsDeposit" value="true" />
Tuesday, February 9, 2016
jQuery UI Library - necessary jQuery file and version
The latest versions of QueryUI library have some quirks to note when adding its necessary references in the section. Below is examples that work and examples that do not work.
Basically when using jQuery UI version 1.11.4 or later, do not use jQuery version 2.x.x. Use jQuery version 1.10.x ~ 1.12.x without the jquery-migrate library.
Basically when using jQuery UI version 1.11.4 or later, do not use jQuery version 2.x.x. Use jQuery version 1.10.x ~ 1.12.x without the jquery-migrate library.
// Works! <link rel="stylesheet" href="jquery-ui-1.11.4/jquery-ui.css"> <script type="text/javascript" src="jquery-1.12.0.js"></script> <script type="text/javascript" src="jquery-ui-1.11.4/jquery-ui.js"></script>
// Works! <link rel="stylesheet" href="jquery-ui-1.11.4/jquery-ui.css"> <script type="text/javascript" src="jquery-1.10.2.js"></script> <script type="text/javascript" src="jquery-ui-1.11.4/jquery-ui.js"></script>
// Does Not Work! <link rel="stylesheet" href="jquery-ui-1.11.4/jquery-ui.css"> <script type="text/javascript" src="jquery-1.12.0.js"></script> <script type="text/javascript" src="jquery-migrate-1.2.1.js"></script> <script type="text/javascript" src="jquery-ui-1.11.4/jquery-ui.js"></script>
// Does Not Work! <link rel="stylesheet" href="jquery-ui-1.11.4/jquery-ui.css"> <script type="text/javascript" src="jquery-1.10.2.js"></script> <script type="text/javascript" src="jquery-migrate-1.2.1.js"></script> <script type="text/javascript" src="jquery-ui-1.11.4/jquery-ui.js"></script>
// Does Not Work! <link rel="stylesheet" href="jquery-ui-1.11.4/jquery-ui.css"> <script type="text/javascript" src="jquery-2.1.4.js"></script> <script type="text/javascript" src="jquery-ui-1.11.4/jquery-ui.js"></script>
Thursday, February 4, 2016
RDLC on WebForm CodeBehind example
Below is a complete source code of a RDLC rendering on aspx webform page.
One important thing to note is that when parameter is used to perform a calculation within the report, the parameter needs to be supplied to the RDLC local report inside ReportViewer. This was a tricky part to understand: I wanted to grab the parameter value from the querystring and feed it directly into a stored procedure in the code-behind, so that I can generate the dataset under the matching "dataset name" embedded in the RDLC report. However, even though the RDLC does not actually use the parameter value to perform query on its own, I still needed to supply the parameter value to the RDLC report separately from feeding it to the stored procedure in the code-behind. Without doing this, the RDLC report would show blank screen.
Another important thing to use is the "SetBasePermissionsForSandboxAppDomain( )" function to allow the local report in ReportViewer to have enough permission so that it is rendered properly.
One important thing to note is that when parameter is used to perform a calculation within the report, the parameter needs to be supplied to the RDLC local report inside ReportViewer. This was a tricky part to understand: I wanted to grab the parameter value from the querystring and feed it directly into a stored procedure in the code-behind, so that I can generate the dataset under the matching "dataset name" embedded in the RDLC report. However, even though the RDLC does not actually use the parameter value to perform query on its own, I still needed to supply the parameter value to the RDLC report separately from feeding it to the stored procedure in the code-behind. Without doing this, the RDLC report would show blank screen.
Another important thing to use is the "SetBasePermissionsForSandboxAppDomain( )" function to allow the local report in ReportViewer to have enough permission so that it is rendered properly.
// RDLC on Webform ("RRA_fax.aspx.cs")
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Security;
using System.Security.Permissions;
using Microsoft.Reporting.WebForms;
using System.Configuration;
using COR.WEB.Helpers;
namespace COR.WEB.Reports
{
public partial class RRA_fax : System.Web.UI.Page
{
int productID;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
initQueryString();
initReport();
}
}
protected void initQueryString()
{
Int32.TryParse(Request.QueryString["ProductID"], out productID);
}
protected void initReport()
{
string connStr = ConfigurationManager
.ConnectionStrings["MyConnString"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connStr))
{
using (SqlCommand cmd = new SqlCommand("proc_ProductDetails", conn))
{
cmd.CommandType = CommandType.StoredProcedure;
// supplying querystring value as parameter
cmd.Parameters.AddWithValue("@productID", productID);
using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
{
DataSet dataSet = new DataSet();
adapter.Fill(dataSet);
// ds_ProductDetails is the dataset name in RDLC file.
ReportDataSource rds1 =
new ReportDataSource("ds_ProductDetails", dataSet.Tables[0]);
ReportViewer1.LocalReport.SetBasePermissionsForSandboxAppDomain(
new PermissionSet(PermissionState.Unrestricted));
ReportViewer1.SizeToReportContent = true;
ReportViewer1.LocalReport.ReportPath =
Server.MapPath("~/RDLC/ProductDetails.rdlc");
// important! - if RDLC originally has a parameter,
// we still have to provide a value for it,
// even though the RDLC does not actually use it
// to perform a query.
ReportParameter param1 =
new ReportParameter("productID", productID.ToString());
ReportViewer1.LocalReport.SetParameters(param1);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(rds1);
ReportViewer1.LocalReport.Refresh();
}
}
}
}
}
}
Render page in different IE version mode
IE 11 has the edge mode set as default rendering engine. Going forward, IE 11 seems to be breaking away with some of the backward-compatible.
I have run into issues with RDLC reports. The letterhead logos are embedded into the report files. They would only appear normally when rendered in IE 9 or 10 mode. A vertical line appears instead when the report is rendered in IE 5, 7, 8 and Edge-mode.
In order to have IE 11 to render the images on the page that contains RDLC report, we can use meta tag as follows to force IE to select a desired version.
I have run into issues with RDLC reports. The letterhead logos are embedded into the report files. They would only appear normally when rendered in IE 9 or 10 mode. A vertical line appears instead when the report is rendered in IE 5, 7, 8 and Edge-mode.
In order to have IE 11 to render the images on the page that contains RDLC report, we can use meta tag as follows to force IE to select a desired version.
<configuration>
...
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="X-UA-Compatible" value="IE=edge" />
<!-- To force IE to render in edge mode. IE=9, IE=10, etc can be used, too. -->
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
Subscribe to:
Posts (Atom)