Slow behavior pushPage Onsen UI - ios

I'm having problems with pushPage slide animation (slow behavior) between pages.
Cordova 4.3.0 / OnsenUI 1.3.0 / iOs 8.3.
Maybe fastClick isn't working!?
Anyone can help me to find this bug?
Code:
Index.html
<ons-sliding-menu
menu-page="pages/menu.html" main-page="pages/page1.html" side="left"
var="menu" type="reveal" max-slide-distance="65%" swipable="true">
</ons-sliding-menu>
page1.html
<ons-navigator var="appNavigator">
<ons-modal var="modal1" style="display:none;" id="modal1">
<ons-icon size="20px" spin="true" icon="ion-load-c"></ons-icon>
<br><br>
Loading...
</ons-modal>
<ons-page ng-controller="controller1">
<ons-pull-hook ng-action="load($done)" var="loader">
<span ng-switch="loader.getCurrentState()">
<span ng-switch-when="initial" style="opacity:0.7;font-size:12px;color:#e23b3c;"><ons-icon style="color:#e23b3c;" size="20px" icon="ion-arrow-down-a"></ons-icon> Baja para actualizar</span>
<span ng-switch-when="preaction" style="opacity:0.7;font-size:12px;color:#e23b3c;"><ons-icon style="color:#e23b3c;" size="20px" icon="ion-arrow-up-a"></ons-icon> Suelta para actualizar</span>
<span ng-switch-when="action" style="opacity:0.7;font-size:12px;color:#e23b3c;"><ons-icon style="color:#e23b3c;" size="20px" spin="true" icon="ion-load-c"></ons-icon> Loading...</span>
</span>
</ons-pull-hook>
<ons-toolbar style="background-color:#e23b3c;">
<div class="left">
<ons-toolbar-button ng-click="menu.toggle()">
<ons-icon icon="ion-navicon" size="28px" fixed-width="false" style="color:#fff;"></ons-icon>
</ons-toolbar-button>
</div>
<div class="center" style="color:#fff;">TITLE...</div>
</ons-toolbar>
<section style="height:100%;">
<ons-list id="lista_descuentos" style="width:100%;height:100%;">
<ul>
<li ng-click="showDetail($index)" ng-repeat="data in todo.all" class="list__item list__item--tappable list__item__line-height list-item-container list__item--chevron">
<div class="ribbon-wrapper-green">
<div class="ribbon-green">{{data.data1}}%</div>
</div>
<div class="list-item-main">
<div class="list-item-left" ng-if="data.data2 == 1">
<img src="urlXXX/{{data.data3}}" class="thumbnail"/>
</div>
<div class="list-item-left" ng-if="data.data2 != 1">
<img src="urlXXX/{{data.data3}}" class="thumbnail desaturate"/>
</div>
<div class="list-item-right">
<div class="list-item-content">
<span class="list-item-name">{{data.data4}}<br/>
<span class="lucent">{{data.data5}}</span>
</span>
<br/>
</div>
</div>
</div>
<span class="list-item-action"></span>
</li>
</ul>
</ons-list>
</section>
</ons-page>
page2.html
<ons-page ng-controller="controller2">
<ons-toolbar style="background-color:#e23b3c;">
<div class="left" style="color:#fff;"><ons-back-button >Back</ons-back-button></div>
<div class="center" style="color:#fff;">{{data1}}</div>
</ons-toolbar>
<div style="height:100%;width:100%;background-position:center; background-repeat:no-repeat; background-size:cover;background-color: #333;background-size:cover;" class="desaturateDiv">
<div class="dots"></div>
<div style="position:absolute;bottom:0;width:100%;height:100%;background-color:rgba(51, 51, 51, 0.6);z-index:90;">
</div>
<div style="position:absolute;bottom:0;width:100%;height:30%;background-color:rgba(51, 51, 51, 0.7);z-index:91;color:#fff;">
{{dato2}}
</div>
</div>
app.js
module.controller('controller1', function($scope, $http, info) {
var firstTime = 1;
var getData = function ($done) {
if (firstTime==1){
modal1.show();
}
$http({method: 'GET', url: info.url}).
success(function(data, status, headers, config) {
if ($done) { $done(); }
$scope.todo = data;
if (firstTime==1){
modal1.hide();
}
}).
error(function(data, status, headers, config) {
if ($done) { $done(); }
alert('error');
modal1.hide();
});
}
// Initial Data Loading
getData();
$scope.load = function($done) {
firstTime = 0;
getData($done);
};
$scope.showDetail = function(index) {
var selectedItem = $scope.todo.all[index];
console.log('asd: '+selectedItem.data1);
$scope.appNavigator.pushPage('pages/page2.html',{data1:selectedItem.data1, data2:selectedItem.data2, data3:selectedItem.data3});
}
});
module.controller('controller2', function($scope) {
$scope.data1 = appNavigator.getCurrentPage().options.data1;
$scope.data2 = appNavigator.getCurrentPage().options.data2;
$scope.data3 = appNavigator.getCurrentPage().options.data3;
});

I get no 300ms delay if the meta viewport tag is configured correctly.
With the following viewport settings pinch zoom is disabled so there should be no delay:
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
Onsen UI will dynamically set the viewport tag if there is none defined.

Related

I want to make the first column use all width when second column is made invisible

i have this html code, and i want to make the first div grab all the width when second div is made invisible, this works, however I wanted to know if it can be done in more graceful way in bootstrap 5.1:
<!DOCTYPE html>
<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KyZXEAg3QhqLMpG8r+8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We" crossorigin="anonymous">
</head>
<body>
<div class=container-fluid>
<div class="row">
<div id="canvas" class="w-75 border">
<p>Hi there</p>
</div>
<div id="submenu" class="w-25 visible">
<p>you there</p>
</div>
</div>
</div>
<button id="button1" type="button" class="btn btn-primary">Click</button>
<script>
const btn = document.getElementById('button1')
const canvas = document.getElementById('canvas')
const subMenu = document.getElementById('submenu')
btn.addEventListener('click', ()=>{
console.log('I am clicked')
if(subMenu.classList.contains('visible')){
canvas.classList.remove('w-75')
canvas.classList.add('w-99')
subMenu.classList.remove('visible')
subMenu.classList.add('invisible')
} else {
canvas.classList.remove('w-99')
canvas.classList.add('w-75')
subMenu.classList.remove('invisible')
subMenu.classList.add('visible')
}
})
</script>
</body>
</html>
You should use the columns instead of w-75, w-25. Then make the first column an auto-layout col so that it grows to fill the width when the other col is hidden. Also use d-none instead of visible...
<div class="container-fluid">
<div class="row">
<div id="canvas" class="col border">
<p>Hi there</p>
</div>
<div id="submenu" class="col-3">
<p>you there</p>
</div>
</div>
</div>
const btn = document.getElementById('button1')
const canvas = document.getElementById('canvas')
const subMenu = document.getElementById('submenu')
btn.addEventListener('click', () => {
console.log('I am clicked')
if (subMenu.classList.contains('d-none')) {
subMenu.classList.remove('d-none')
} else {
subMenu.classList.add('d-none')
}
})
https://codeply.com/p/VsC8j2BlF9
Also, it would be easier to use the Bootstrap collapse component. Then you don't need the extra JavaScript..
https://codeply.com/p/tBb263fzdp

MVC Project memory leaking, how to fix it?

I've tried everything about that but i couldnt find a solution. On local, there's no problem. But when i publish to provider hosting. Memory leaking issue is coming out and IIS Recylcling every 75 seconds. I Used memory profiler but, no issue on local like i said. Here's my basecontroller code. Can it cause a memory leak?. And i use tags in layout. Maybe it causes a memory leak. If you want layout code i can add. For now, my basecontroller code be like;
public class BaseController : Controller
{
public BaseController()
{
GC.Collect(2, GCCollectionMode.Forced, true);
GC.WaitForPendingFinalizers();
}
internal void ShowErrorMessage(string message)
{
ViewBag.ErrorMessage = message;
}
public List<Categories> GetCategories()
{
var catserv = new CategoryService();
return catserv.GetAll().Where(x => x.Status == DataStatus.Active).ToList();
}
public List<Products> GetProducts()
{
var prodserv = new ProductService();
return prodserv.GetAll().ToList();
}
public bool CheckAdmin()
{
string username = User.Identity.Name;
var member = new MemberService();
var result = member.GetUserName(username);
if (result.Data.IsAdmin != 1)
return false;
else
return true;
}
public string SamePath()
{
return Request.UrlReferrer.PathAndQuery.ToString();
}
}
GetCategories method is being used for layout. I couldnt add viewmodel entity and i added this method below.
Check my admincontroller and layout.
[HttpPost]
public ActionResult Login(Member memb)
{
var memberservice = new MemberService();
var getMemberResult = memberservice.Auth(memb.UserName, memb.Password);
if (getMemberResult.HasError)
{
ViewBag.mesaj = getMemberResult.ResultMessage;
return View();
}
if (getMemberResult.Data.Status == DataStatus.Banned)
{
return RedirectToAction("BannedUser");
}
FormsAuthentication.SetAuthCookie(getMemberResult.Data.UserName, false);
return RedirectToAction("Anasayfa", "Magaza");
}
And my layout.. and actually it has var baseController = ViewContext.Controller as web2.Controllers.BaseController; on the top
<body>
<div class="banner_bg_main">
<!-- header top section start -->
<div class="container">
<div class="header_section_top">
<div class="row">
<div class="col-sm-12">
<div class="custom_menu">
<ul>
<li>Kusursuz Tasarım</li>
<li>Profesyonel Çalışmalar</li>
<li>Uygun Fiyat Politikası</li>
<li>Promosyon Ürünleri</li>
<li>Matbaa Ürünleri</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<!-- header top section start -->
<!-- logo section start -->
<div class="logo_section">
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="logo"></div>
</div>
</div>
</div>
</div>
<!-- logo section end -->
<!-- header section start -->
<div class="banner_section layout_padding">
<div class="container">
<div id="my_slider" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<div class="row">
<div class="col-sm-12">
<h1 class="banner_taital">%100<br>Fiyat Garantisi</h1>
<div class="buynow_bt">Sipariş Ver</div>
</div>
</div>
</div>
<div class="carousel-item">
<div class="row">
<div class="col-sm-12">
<h1 class="banner_taital">Hemen Ürün<br>Siparişinizi Verin</h1>
<div class="buynow_bt">Sipariş Ver</div>
</div>
</div>
</div>
<div class="carousel-item">
<div class="row">
<div class="col-sm-12">
<h1 class="banner_taital">Tamamen isteğe<br>UYGUN TASARIM</h1>
<div class="buynow_bt">Sipariş Ver</div>
</div>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#my_slider" role="button" data-slide="prev">
<i class="fa fa-angle-left"></i>
</a>
<a class="carousel-control-next" href="#my_slider" role="button" data-slide="next">
<i class="fa fa-angle-right"></i>
</a>
</div>
</div>
</div>
<div class="header_section pb-3">
<div class="container">
<div class="containt_main justify-content-center">
<div id="mySidenav" class="sidenav">
×
<a href=#Url.Action("Anasayfa","Magaza")>Anasayfa</a>
<a href=#Url.Action("Urunler","Magaza")>Ürünler</a>
#if (User.Identity.IsAuthenticated)
{
<a href=#Url.Action("Menu","Admin")>Admin Menü</a>
}
</div>
</div>
<div class="containt_main">
<span class="toggle_icon" onclick="openNav()"><img src="~/Content/images/toggle-icon.png"></span>
<div class="main">
<!-- Another variation with a button -->
#using (Html.BeginForm("Urunler", "Magaza", FormMethod.Get))
{
<div class="input-group">
#Html.TextBox("Ara", "", new { #class = "form-control", #placeholder = "Ürün Arayın", #type = "text" })
<div class="input-group-append">
<button class="btn btn-secondary" type="submit" style="background-color: #f26522; border-color:#f26522">
<i class="fa fa-search"></i>
</button>
</div>
</div>
}
</div>
<div class="header_box">
<div class="login_menu">
<!--<ul>
<li><a href="#">
<i class="fa fa-shopping-cart" aria-hidden="true"></i>
<span class="padding_10">Cart</span></a>
</li>
<li><a href="#">
<i class="fa fa-user" aria-hidden="true"></i>
<span class="padding_10">Cart</span></a>
</li>
</ul> -->
</div>
</div>
</div>
<div class="text-center mt-3">
<button class="btn btn-secondary dropdown-toggle mb-3" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Kategoriler
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
#foreach (var item in baseController.GetCategories())
{
<a class="dropdown-item" href="#Url.Action("Urunler","Magaza", new {#kategori = item.Id })">#item.CategoryName</a>
}
</div>
</div>
</div>
</div>
<!-- header section end -->
<!-- banner section start -->
<!-- banner section end -->
</div>
#RenderBody()
<div class="footer_section layout_padding">
<div class="container">
<div class="footer_logo"><img style="height:100px;" src="~/Content/img/logo.png"></div>
<div class="footer_menu">
<ul>
<li>
<li>Uygun Fiyat Politikası</li>
<li>%100 Memnuniyet</li>
</ul>
<br />
<ul>
<li>Anasayfa</h3></li>
</ul>
<br />
<ul>
<li><h3 style="color:white">Adres</h3>Rami Cuma Mah.<br /> Oruç Sk. No:20B<br />Eyüp/İstanbul</li>
</ul>
</div>
<div class="location_main">Whatsapp Hattı İçin Tıkla</div>
<div class="location_main"><img class="img-responsive" style="height:55px;" src="~/Content/img/instalogo.png" /></div>
</div>
</div>
<script src="~/Content/js/jquery.min.js"></script>
<script src="~/Content/js/bootstrap.bundle.min.js"></script>
<script src="~/Content/js/jquery-3.0.0.min.js"></script>
<script src="~/Content/js/plugin.js"></script>
<!-- sidebar -->
<script src="~/Content/css/jquery.mCustomScrollbar.concat.min.js"></script>
<script src="~/Content/css/custom.js"></script>
<script type="text/javascript" src="~/Content/js/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2#10"charset="utf-8"></script>
<script>
var counter = 0;
function openNav() {
counter++;
if (counter % 2 == 1)
document.getElementById("mySidenav").style.width = "250px";
else
document.getElementById("mySidenav").style.width = "0";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
}
</script>
#if (ViewBag.ErrorMessage != null || TempData["Fail"] != null)
{
<script>
swal.fire({
title: "Olmadı be",
text: '#ViewBag.ErrorMessage',
icon: "error",
});
</script>
}
#if (ViewBag.successtoindex != null)
{
<script>
swal.fire({
icon: 'info',
title: 'Hadi Anasayfaya Dönelim',
text: '#ViewBag.successtoindex',
button: 'Hadi Anasayfaya Dönelim!'
}).then(function () {
window.location = "/";
});
</script>
}
#if (ViewBag.success != null || TempData["Success"] != null)
{
<script>
swal.fire({
title: "Mükemmel",
text: '#ViewBag.success',
icon: "success",
button: "Aww yiss!",
});
</script>
}
#if (ViewBag.successadminmenu != null)
{
<script>
swal.fire({
title: "Başarılı",
text: '#ViewBag.successadminmenu',
icon: "success",
button: "Muhteşem!",
}).then(function () {
window.location = "menu";
});;
</script>
}

jquery / Ajax "undefined" error

i am trying to get an image uploader working inside my MVC project, but everytime i click the upload file button, i get "Error undefined", i am not sure where i am going wrong.
The page is a partial view, loaded inside a #Html.BeginForm . below is the code i am using.
Index.cshtml
#using (Html.BeginForm("Register", "Account", FormMethod.Post))
{
#Html.AntiForgeryToken()
<div class="container">
<div class="row">
<article class="col-sm-12 col-md-12 col-lg-12 sortable-grid ui-sortable">
<div id="wid-id-0">
<!-- widget div-->
<div role="content">
<!-- widget content -->
<div class="widget-body">
<div class="row" style="background: white">
<form id="wizard-1" novalidate="novalidate">
<div id="bootstrap-wizard-1" class="col-sm-12">
<div class="tab-content">
#*Tab 1 (Step 1)*#
<div class="tab-pane active" id="tab1">
<br>
#Html.Partial("Registration/_Step1")
<div class="form-actions">
<div class="row">
<div class="col-sm-12">
<ul class="pager wizard no-margin">
<li class="previous disabled">
Previous
</li>
<li data-target="#step2" class="next">
Next
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="form-bootstrapWizard">
<ul class="bootstrapWizard form-wizard" style="background: coral">
<li class="active" data-target="#step1">
<span class="step">1</span> <span class="title">Step 1: Profile Information</span>
</li>
<li data-target="#step2" class="">
<span class="step">2</span> <span class="title">Step 2: Profile Picture</span>
</li>
<li data-target="#step3" class="">
<span class="step">3</span> <span class="title">Step 3: Identification</span>
</li>
<li data-target="#step4">
<span class="step">4</span> <span class="title">Step 4: Submit Profile</span>
</li>
</ul>
<div class="clearfix"></div>
</div>
</div>
</form>
</div>
</div>
<!-- end widget content -->
</div>
<!-- end widget div -->
</div>
<!-- end widget -->
</article>
</div>
</div>
}
_Step1.cshtml
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$(document).ready(function () {
$("#Upload").click(function (e) {
e.preventDefault();
var formData = new FormData();
var totalFiles = document.getElementById("FileUpload").files.length;
for (var i = 0; i < totalFiles; i++)
{
var file = document.getElementById("FileUpload").files[i];
formData.append("FileUpload", file);
}
$.ajax({
type: "POST",
url: '#Url.Action("UploadFiles", "Account")',
data: formData,
dataType: 'json',
contentType: false,
processData: false,
success: function (response) {
alert('succes!!');
},
error: function (error) {
alert("error: " + error.statusMessage);
}
});
});
});
</script>
<table align="center">
<tr>
<td style="text-align: center;"><label>Upload Profile Picture</label></td>
<td></td>
</tr>
<tr>
<td valign="top"><img id="imgPreview" src="~/Content/Images/upload_holder.PNG" class="img-holder" style="width: 180px; height: 180px;" /></td>
<td>
#*<input type="submit" class="btn btn-lg" style="width: 200px; background: #0091d9; color: white;" value="Upload Photo" />*#
#*<input id="input-4" name="input4[]" type="file" multiple class="file-loading" style="width: 200px; background: #0091d9; color: white;" value="Upload Photo">*#
<input type="file" id="FileUpload" multiple />
<input type="submit" id="Upload" value="Upload"/>
<br />
<br />
<label>Acceptable file formats: jpg, gif or png file</label>
<br />
<label>Under 1 MB</label>
</td>
</tr>
</table>
any help is greatly appreciated!
EdIT: Below is the controller function, but its never hit.
[HttpPost]
public ActionResult UploadFiles()
{
// Checking no of files injected in Request object
if (Request.Files.Count > 0)
{
try
{
// Get all files from Request object
HttpFileCollectionBase files = Request.Files;
for (int i = 0; i < files.Count; i++)
{
//string path = AppDomain.CurrentDomain.BaseDirectory + "Uploads/";
//string filename = Path.GetFileName(Request.Files[i].FileName);
HttpPostedFileBase file = files[i];
string fname;
// Checking for Internet Explorer
if (Request.Browser.Browser.ToUpper() == "IE" || Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER")
{
string[] testfiles = file.FileName.Split(new char[] { '\\' });
fname = testfiles[testfiles.Length - 1];
}
else
{
fname = file.FileName;
}
// Get the complete folder path and store the file inside it.
fname = Path.Combine(Server.MapPath("~/Uploads/"), fname);
file.SaveAs(fname);
}
// Returns message that successfully uploaded
return Json("File Uploaded Successfully!");
}
catch (Exception ex)
{
return Json("Error occurred. Error details: " + ex.Message);
}
}
else
{
return Json("No files selected.");
}
}

AngularJS doesn't work in MVC Partial Views

I'm currently working on a ASP.NET MVC project. The sites of the web application are created with Bootstrap. Later I added some AngularJS script to be able to translate the page into different languages. This works fine for all the pages, but not so if a partial view is loaded from a page.
So, for example I have a page to search for rollout objects by name or host name. On the page all the angular expressions in curly braces are evaluated properly and are replaced with strings in several languages by using a translate script. Now if I filter the objects by one of the three attributes the partial view for that page is loaded showing the results of the search, but here are the angular expressions not evaluated and it just shows the expressions themselves.
Here is the page where it works properly:
#{
ViewBag.Title = "{{ 'ROLLOUT-OBJECT_MANAGEMENT.TITLE' | translate }}";
}
<!-- html -->
<div style="font-size: 20px; margin-top: 20px; margin-bottom: 20px;">
<div class="gray-background list-group-item" translate="{{'ROLLOUT-OBJECT_MANAGEMENT.TITLE'}}"></div>
</div>
<div class="list-group">
<div class="gray-background list-group-item">
<div class="row margin-bottom">
<div class="col-md-3">
<h6 translate="{{'ROLLOUT-OBJECT_MANAGEMENT.FIRST_NAME'}}"></h6>
</div>
<div class="col-md-3">
<h6 translate="{{'ROLLOUT-OBJECT_MANAGEMENT.SURNAME'}}"></h6>
</div>
<div class="col-md-3">
<h6 translate="{{'ROLLOUT-OBJECT_MANAGEMENT.HOST_NAME'}}"></h6>
</div>
</div>
<div class="row margin-bottom">
<div class="col-md-3">
<!-- referenced in getPartial() -->
<input type="text" class="form-control" id="iFirstName" name="iFirstName" placeholder="">
</div>
<div class="col-md-3">
<!-- referenced in getPartial() -->
<input type="text" class="form-control" id="iSurName" name="iSurName" placeholder="">
</div>
<div class="col-md-3">
<!-- referenced in getPartial() -->
<input type="text" class="form-control" id="iHostName" name="iHostName" placeholder="">
</div>
<div class="col-md-3">
<!-- getPartial() added to click through javascript-->
<button type="submit" class="btn btn-primary btn-block" id="iButton"><span translate="{{'ROLLOUT-OBJECT_MANAGEMENT.BUTTON_SEARCH'}}"></span><span class="white-color glyphicon glyphicon-search"></span></button>
</div>
</div>
</div>
</div>
<div class="list-group">
<div class="gray-background list-group-item">
<h5><span translate="{{'ROLLOUT-OBJECT_MANAGEMENT.RESULTS'}}"></span><span class="purple-color glyphicon glyphicon-globe"></span></h5>
</div>
<!-- referenced in getPartial() -->
<div class="gray-background list-group-item">
<div class="row">
<div class="col-md-12" id="partialViewContainer">
#{Html.RenderPartial("_RolloutObjectManagementResultsPartial");}
</div>
</div>
</div>
</div>
<!-- layout -->
#Styles.Render(
"~/content/chosen/chosen.css",
"~/content/chosen/prism.css",
"~/content/chosen/style.css",
"~/content/bootstrap.css",
"~/content/Site.css")
<!-- javascript -->
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/chosen/chosen.jquery.js"></script>
<script src="~/Scripts/chosen/prism.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
<script>
var config = {
'.chosen-select': {},
'.chosen-select-deselect': { allow_single_deselect: true },
'.chosen-select-no-single': { disable_search_threshold: 10 },
'.chosen-select-no-results': { no_results_text: 'Oops, nothing found!' },
'.chosen-select-width': { width: "95%" }
}
for (var selector in config) {
$(selector).chosen(config[selector]);
}
</script>
<script>
//add functionality to button
$('#iButton').click(function () {
getPartial('0');
});
</script>
<script>
function previous() {
var temp = document.getElementById("hPage").value;
//alert(temp);//debug
if (temp > 0) {
temp = --temp;
}
getPartial(temp);
}
function next() {
var temp = document.getElementById("hPage").value;
//alert(temp);//debug
temp = ++temp;
getPartial(temp);
}
</script>
<script>
function getPartial(newPage) {
//get search values
var tempFirst = document.getElementById("iFirstName");
var tempSur = document.getElementById("iSurName");
var tempHost = document.getElementById("iHostName");
var firstResult = tempFirst.value;
var surResult = tempSur.value;
var hostResult = tempHost.value;
//ajax call
$.ajax({
url: "_RolloutObjectManagementResultsPartial",
type: "POST",
data: { firstName: firstResult, surName: surResult, hostName: hostResult, page: newPage, count: 10 },
dataType: "html",
error: function (xhr) {
//alert(xhr.responseText);//debug
},
success: function (result) {
$("#partialViewContainer").html(result).find("select").each(function () {
$(this).chosen({});
})
},
complete: function () {
//alert("everything worked");//debug
}
});
}
</script>
And here is the partial view where it doesn't work (important are the expressions in {{...}}:
<!-- Import needed namespaces -->
#using RolloutTool.BusinessLayer.Foundation
#using RolloutTool.Utility
<!-- Initializing needed variables -->
#{
List<RolloutObject> RolloutObjects = ViewContext.Controller.ViewBag.RolloutObjects;
List<Cluster> Clusters = ViewContext.Controller.ViewBag.Clusters;
string name = "";
int count = 0;
string rowID = "";
int page = 0;
if (ViewContext.Controller.ViewBag.Page != null)
{
page = ViewContext.Controller.ViewBag.Page;
}
}
<!-- html elements -->
<div class="row">
<div class="col-md-12">
<table class="table">
<thead>
<tr>
<th style="width:25%"><h6 translate="{{'ROLLOUT-OBJECT_MANAGEMENT.EMPLOYEE'}}"></h6></th>
<th style="width:20%"><h6 translate="{{'ROLLOUT-OBJECT_MANAGEMENT.WORK_STATION'}}"></h6></th>
<th class="text-center" style="width:15%"><h6 translate="{{'ROLLOUT-OBJECT_MANAGEMENT.EDIT'}}"></h6></th>
<th class="text-center" style="width:25%"><h6 translate="{{'ROLLOUT-OBJECT_MANAGEMENT.CLUSTER'}}"></h6></th>
<th class="text-center" style="width:15%"><h6 translate="{{'ROLLOUT-OBJECT_MANAGEMENT.ASSIGN'}}"></h6></th>
</tr>
</thead>
<tbody>
<!-- creating all RolloutObject Table rows -->
#foreach (RolloutObject ro in RolloutObjects)
{
<!-- generating rowID -->
rowID = "row" + Convert.ToString(count);
count++;
<!-- generating the full employee name -->
name = Functions.TryGetValue(ro.Employee.FirstName) + " " + Functions.TryGetValue(ro.Employee.SecondName) + " " + Functions.TryGetValue(ro.Employee.Name);
<tr id="#rowID">
<td>#name</td>
<td id="#Convert.ToString(rowID + "_hn")">#Convert.ToString(Functions.TryGetValue(ro.Hostname))</td>
<!-- generate link to right rolloutobjectedit -->
<td class="text-center"><span class="btn-pencil glyphicon glyphicon-pencil blue-color glyph-hov" onclick="location.href='#Url.Action("RolloutObjectEdit", "RolloutObject", new {hostName = ro.Hostname })'"></span></td>
<!-- generating the link for cluster addition and populating cluster dropdown -->
<td class="text-center">
<div class="row">
<div class="col-sm-12">
<select class="chosen-select no-margin" style="width:100%" id="#Convert.ToString(rowID + "_cl")" name="iCluster" data-placeholder="Cluster">
#if (ro.Cluster != null)
{
<option selected>#Convert.ToString(Functions.TryGetValue(ro.Cluster.Name))</option>
}
else
{
<option></option>
}
#foreach (Cluster cluster in Clusters)
{
<option>#Convert.ToString(Functions.TryGetValue(cluster.Name))</option>
}
</select>
</div>
</div>
</td>
<td class="text-center"><span class="btn-ok glyphicon glyphicon-ok green-color glyph-hov" onclick="callAjax('#rowID')" /></td>
</tr>
}
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="col-md-12">
<input class="hidden" id="hPage" value="#Convert.ToString(page)" />
<nav>
<ul class="pager">
<li class="pull-left"><a class="btn-paging glyphicon glyphicon-arrow-left" onclick="previous()"></a></li>
<li class="pull-right"><a class="btn-paging glyphicon glyphicon-arrow-right" onclick="next()"></a></li>
</ul>
</nav>
</div>
</div>
<!-- javascript -->
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/chosen/chosen.jquery.js"></script>
<script src="~/Scripts/chosen/prism.js"></script>
<script>
function callAjax(idRow) {
//get row values
var tempTD = document.getElementById(idRow + "_hn");
var tempSelect = document.getElementById(idRow + "_cl");
var tempHostName = tempTD.textContent;
var tempCluster = tempSelect.options[tempSelect.selectedIndex].text;
//ajax call
$.ajax({
url: "AddToCluster",
type: "POST",
data: { clusterName: tempCluster, hostName: tempHostName },
dataType: "html",
error: function (xhr) {
alert(xhr.responseText);
},
success: function (result) {
},
complete: function () {
//alert("everything worked");//debug
}
});
}
</script>
<script>
function previous() {
var temp = document.getElementById("hPage").value;
//alert(temp);//debug
if (temp > 0) {
temp = --temp;
}
getPartial(temp);
}
function next() {
var temp = document.getElementById("hPage").value;
//alert(temp);//debug
temp = ++temp;
getPartial(temp);
}
</script>
<script>
function getPartial(newPage) {
//get search values
var tempFirst = document.getElementById("iFirstName");
var tempSur = document.getElementById("iSurName");
var tempHost = document.getElementById("iHostName");
var firstResult = tempFirst.value;
var surResult = tempSur.value;
var hostResult = tempHost.value;
//ajax call
$.ajax({
url: "_RolloutObjectManagementResultsPartial",
type: "POST",
data: { firstName: firstResult, surName: surResult, hostName: hostResult, page: newPage, count: 10 },
dataType: "html",
error: function (xhr) {
alert(xhr.responseText);
},
success: function (result) {
$("#partialViewContainer").html(result).find("select").each(function () {
$(this).chosen({});
})
},
complete: function () {
//alert("everything worked");//debug
}
});
}
</script>
This is the _Layout.cshtml where the scripts are contained and loaded:
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>#ViewBag.Title - {{ 'TITLE.PROGRAM' | translate }}</title>
#Styles.Render(
"~/Content/css",
"~/Content/flag-icon-css-master/assets/docs.css",
"~/Content/flag-icon-css-master/css/flag-icon.min.css",
"~/Content/Site.css")
<script src="~/Scripts/angular/angular.js"></script>
<script src="~/Scripts/angular/angular-translate.js"></script>
<script src="~/Scripts/angular/angular-cookies.min.js"></script>
<script src="~/Scripts/angular/translate.js"></script>
<script src="~/Scripts/angular/angular-route.min.js"></script>
<script src="~/Scripts/angular/angular-translate-storage-cookie.min.js"></script>
<script src="~/Scripts/angular/angular-translate-storage-local.min.js"></script>
</head>
<body ng-controller="Ctrl">
<!-- Here is the html for the navigation bar etc. -->
#Scripts.Render("~/bundles/jquery")
#Scripts.Render("~/bundles/bootstrap")
#RenderSection("scripts", required: false)
</body>
</html>
I am really not an expert on AngularJS as I only wanted to provide some cool translation feature, but I hope you guys have an idea why it doesn't work in the partial views.
Its just that you need to call the partial view using ng-include("'controller/action'"). Apostrophe(') is important while writing url.
Example
<div id="TestDiv" ng-include="templateUrl"></div>
and inside the angular controller
var app = angular.module("Layout", []);
app.controller("LoadPage", function ($scope, $http, $sce) {
//Initially
$scope.templateUrl = '/Home/DefaultPage';
// To dynamically change the URL.
$scope.NewProjFn = function () {
$scope.templateUrl = '/Home/ProjectPage';
};
});
It might well not at all be difficult for you to re-implement it but by using ng-include you also need not to make an ajax call. It do it all by itself which includes ajax call, compilation and display. But the functions like ng-click and other events will not work as its a one time compilation process.

jquery mobile dialog does not show

Hi I have the following page
<div data-role="page" id="blockedusers">
<?php
include 'homeheader.php';
?>
<div data-role="header">
Log Uit
<h1>Blocklijst</h1>
</div><!-- /header -->
<div data-role="content">
<div class="grid_outer" id="grid_outer_blocklist" style="width: 295px; margin-left: auto; margin-right: auto;">
<div class="grid_inner" id="grid_inner_blocklist">
<h2 class="h2_header">Geblokkeerde gebruikers</h2>
<?php
show_blocked_users($blockedusers);
?>
</div>
</div>
</div>
<div data-role="navbar">
<ul>
<li>
terug
</li>
</ul>
</div><!-- /navbar -->
<div data-role="footer">
<h4>Blocklijst</h4>
</div>
</div><!-- /content -->
<div data-role="dialog" id="confirmbox">
<div data-role="header" data-icon="false">
<h1>Bevestig</h1>
</div><!-- /header -->
<div data-role="content">
<h3 id="confirmMsg">Bevestig</h3>
<br>
<center>
Yes
No
</center>
</div>
</div>
And I have the following javascript in an external js file
$(document).on('pagebeforeshow', '#blockedusers', function() {
alert('pagebeforeshow blockedusers');
$('[id=unblocklink]').click(function(e) {
e.preventDefault();
var userid = $(this).attr('userid');
alert('unblocklink clicked userid ' + userid);
showConfirm("Weet je zeker dat je deze gebruiker wilt deblokkeren?", function() {
$.ajax({
async : false,
url : "../php/process_unblock_user.php?userid=" + userid,
success : function(data) {
if (data != "") {
// in case of error
alert(data);
} else {
alert("Gebruiker gedeblokkeerd!");
window.location.reload(true);
}
}
});
});
});
// confirm dialog
function showConfirm(msg, callback) {
alert('showing dialog1');
$("#confirmMsg").text(msg);
$("#confirmbox .btnConfirmYes").on("click.confirmbox", function() {
$("#confirmbox").dialog("close");
callback();
});
$("#confirmbox .btnConfirmNo").off("click.confirmbox", function(r) {
});
alert('showing dialog2');
$.mobile.changePage('#confirmbox', {
allowSamePageTransition : true
});
}
});
The problem is, the confirmdialog never shows (???). I added the javascript on the same page but then I have issues with the unblocklink.
Ok I found a solution to fix the issue:
When navigating to the blockedusers page from the home page, I need to do it the following way:
$('#blockedusers').click(function(e) {
window.location.href = "blockedusers.php";
});
Only then the confirmbox is available in the DOM.
This does not work:
$.mobile.changePage('blockedusers.php');
Hope this solution helps more people out.

Resources