Kendo UI template issue - kendo-ui

I would like to do sth like this http://jsfiddle.net/kfEfw/115/
but in the kendo.template( .... ) I want to check a variable's value.
In the specific example it doesn't recognize x variable and I would like
to know if there is a way to pass x in the template.
var temp = 0; //i want to pass this variable in the template and check it's value
/if temp = 0 I need to render sth and if temp has other value I want to render sth else
window.kendouiTemplate = kendo.template("<div><h1 class='header'><#= data.header#></h1><ul
class='list'><# for (var i = 0, l = data.list.length; i < l; i++) {
#><#if(data.list[i]%2==0){#><li class='item'><#= data.list[i] #></li><#}#><# } #></ul>
</div>", {useWithBlock:false});
Thanks in advance,
Artemis

See the demo here --> http://demos.kendoui.com/web/templates/index.html
so in your case
HTML
<div id="results"></div>
<script type="text/x-kendo-template" id="template">
<div>
<h1 class='header'><#= data.header #></h1>
<h2 class='header2'><#= data.header2 #></h2>
<h3 class='header3'><#= data.header3 #></h3>
<h4 class='header4'><#= data.header4 #></h4>
<h5 class='header5'><#= data.header5 #></h5>
<h6 class='header6'><#= data.header6 #></h6>
<ul class='list'>
<# for (var i=0 , l=data.list.length; i < l; i++) { #>
<#if(data.list[i]%2==0){#>
<li class='item'>
<#=data.list[i] #>
</li>
<#}#>
<# } #>
</ul>
</div>
</script>
JavaScript
window.sharedVariables = {
header: "Header",
header2: "Header2",
header3: "Header3",
header4: "Header4",
header5: "Header5",
header6: "Header6",
list: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
};
var temp = 0; //i want to pass this variable in the template and check it's value
var template = kendo.template($("#template").html()); // your kendo template
function preview() {
$("#results").html(template(sharedVariables));
}
preview();

Related

Scrollspy Uikit 3 framework and count up

i am a beginer in frontend and javascript hard for me :( I want to make count numbers with component scrollspy uikit 3 without jquery https://getuikit.com/docs/scrollspy
I made like this, but it's not working
<span id="number"></span>
<script>
UIkit.scrollspy('#number', 'inview', function () {
const countUp = new CountUp('number', 0, 1000 );
countUp.start();
});
</script>
I created a script for this.
var util = UIkit.util;
var el = util.$('#heading');
var textIndex = 0;
UIkit.scrollspy(el, {repeat: true, delay: 100});
util.on(el,'inview', function (){
function counter( start, end, duration) {
let current = start,
range = end - start,
increment = end > start ? 1 : -1,
step = Math.abs(Math.floor(duration / range)),
timer = setInterval(() => {
current += increment;
el.textContent = current;
if (current == end) {
clearInterval(timer);
}
}, step);
}
counter(0, 100, 3000);
});
util.on(el, 'outview', function(){
el.textContent = 0;
});
<!-- UIkit CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/uikit#3.6.22/dist/css/uikit.min.css" />
<!-- UIkit JS -->
<script src="https://cdn.jsdelivr.net/npm/uikit#3.6.22/dist/js/uikit.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/uikit#3.6.22/dist/js/uikit-icons.min.js"></script>
<section class="uk-section uk-section-primary" uk-height-viewport="offset-top: true">
<div class="uk-container">
<div class="uk-text-center">
<h1 >SECTION 1</h1>
Source Code for Number Increment
</div>
<div class="uk-text-center uk-margin-medium-top">
<a class="uk-link-reset" href="#section" uk-scroll>Scroll</a>
</div>
</div>
</section>
<section class="uk-section uk-section-secondary" id="section">
<div class="uk-container">
<h1 class="uk-text-center" id="heading">0</h1>
</div>
</section>
You need to listen inview and outview event. Here is the method:
UIkit.util.on(element, 'event', function(){
//your code will be here here
});

Dynamically Binding the the Oracle jet switcher slot to the oracle jet add and remove tab(Make switcher slot dynamic in oracle jet)

I want to make tab switcher auto decide the slot for the switcher but when I am trying to make it dynamic with the help of observable no data is showing the tab content area until I write the slot area statically. With observable variable, the slot is not getting the selected Slot value.
Please check how I can do this.
slot = [[selectedSlot]] //using for the slot value in html
this.selectedSlot = ko.observable('settings');
<div id="tabbardemo">
<oj-dialog class="tab-dialog hidden" id="tabDialog" dialog-title="Tab data">
<div slot="body">
<oj-form-layout>
<oj-input-text id="t1" value="{{newTabTitle}}" label-hint="Title"></oj-input-text>
</oj-form-layout>
</div>
<div slot="footer">
<oj-button id="idOK" on-oj-action="[[addTab]]">OK</oj-button>
<oj-button id="idCancel" on-oj-action="[[closeDialog]]">Cancel</oj-button>
</div>
</oj-dialog>
<oj-button id="addTab" on-oj-action="[[openDialog]]">Add Tab</oj-button>
<br/>
<br/>
<oj-tab-bar contextmenu="tabmenu" id="hnavlist" selection="{{selectedItem}}" current-item="{{currentItem}}" edge="top" data="[[dataProvider]]"
on-oj-remove="[[onRemove]]">
<template slot="itemTemplate" data-oj-as="item">
<li class="oj-removable" :class="[[{'oj-disabled' : item.data.disabled}]]">
<a href="#">
<oj-bind-text value="[[item.data.name]]"></oj-bind-text>
</a>
</li>
</template>
<oj-menu slot="contextMenu" class="hidden" aria-label="Actions">
<oj-option data-oj-command="oj-tabbar-remove">
Removable
</oj-option>
</oj-menu>
</oj-tab-bar>
<oj-switcher value="[[selectedItem]]">
<div slot="[[selectedSlot]]"
id="home-tab-panel"
role="tabpanel"
aria-labelledby="home-tab">
<div class="demo-tab-content-style">
<h2>Home page content area</h2>
</div>
</div>
<div slot="tools"
id="tools-tab-panel"
role="tabpanel"
aria-labelledby="tools-tab">
<div class="demo-tab-content-style">
<h1>Tools Area</h1>
</div>
</div>
<div slot="base"
id="base-tab-panel"
role="tabpanel"
aria-labelledby="ba`enter code here`se-tab">
<div class="demo-tab-content-style">
<h1>Base Tab</h1>
</div>
</div>
</oj-switcher>
<br>
<div>
<p class="bold">Last selected list item:
<span id="results">
<oj-bind-text value="[[selectedItem]]"></oj-bind-text>
</span>
</p>
</div>
</div>
JS code below
require(['ojs/ojcontext',
'knockout',
'ojs/ojbootstrap',
'ojs/ojarraydataprovider',
'ojs/ojknockout',
'ojs/ojnavigationlist',
'ojs/ojconveyorbelt',
'ojs/ojdialog',
'ojs/ojbutton',
'ojs/ojinputtext',
'ojs/ojformlayout',
'ojs/ojswitcher',
],
function (Context, ko, Bootstrap, ArrayDataProvider) { // this callback gets executed when all required modules are loaded
function ViewModel() {
this.data = ko.observableArray([{
name: 'Settings',
id: 'settings'
},
{
name: 'Tools',
id: 'tools'
},
{
name: 'Base',
id: 'base'
}
]);
this.selectedSlot = ko.observable('settings'); //Sepecifically mentioned to show what it is the objective
this.dataProvider = new ArrayDataProvider(this.data, { keyAttributes: 'id' });
this.selectedItem = ko.observable('settings');
this.currentItem = ko.observable();
this.tabCount = 0;
this.newTabTitle = ko.observable();
this.delete = (function (id) {
var hnavlist = document.getElementById('hnavlist');
var items = this.data();
for (var i = 0; i < items.length; i++) {
if (items[i].id === id) {
this.data.splice(i, 1);
Context.getContext(hnavlist)
.getBusyContext()
.whenReady()
.then(function () {
hnavlist.focus();
});
break;
}
}
}).bind(this);
this.onRemove = (function (event) {
this.delete(event.detail.key);
event.preventDefault();
event.stopPropagation();
}).bind(this);
this.openDialog = (function () {
this.tabCount += 1;
this.newTabTitle('Tab ' + this.tabCount);
document.getElementById('tabDialog').open();
}).bind(this);
this.closeDialog = function () {
document.getElementById('tabDialog').close();
};
this.addTab = (function () {
var title = this.newTabTitle();
var tabid = 'tid' + this.tabCount;
this.data.push({
name: title,
id: tabid
});
this.closeDialog();
}).bind(this);
}
Bootstrap.whenDocumentReady().then(function () {
ko.applyBindings(new ViewModel(), document.getElementById('tabbardemo'));
});
}
);
It is a bit complex to understand when you copy from JET cookbook. You have done almost everything right. Just make the following changes:
1) Remove this:
Bootstrap.whenDocumentReady().then(function () {
ko.applyBindings(new ViewModel(), document.getElementById('tabbardemo'));
});
Why? The bootstrapping is required once per application, which is done inside your main.js file.
2) Replace require by define
Why? Require block is again maintained in main.js, where your required modules are pre-loaded. All subsequent viewModels have define block
3) Return an instance of your ViewModel
define([
... Your imports
],
function (Context, ko, Bootstrap, ArrayDataProvider) { // this callback gets executed when all required modules are loaded
function ViewModel() {
// Your code
}
return ViewModel;
});

Change pricing based on whether checkbox is checked or not in Laravel

I am trying to calculate some shipping prices in Laravel. There are only two options based on weight and I have that working with an if/else statement. The client would like to add an option that if someone would like to ship their items faster and they are under the Priority weight, they can for the additional shipping cost. I set up a checkbox in my blade template but am not 100% sure how to implement it. I would assume I have to do some kind if isset statement.
Here is the code in my blade template:
#if( $total_weight <= 16.00)
<li class="payment__item">
<label for="priority">Priority Mail</label>
<span style="padding-top: 2.5%;">
<input type="checkbox" name="priority" value="1" {{ $shipping_cost['attributes']['priority'] == '10' ? 'checked="checked"' : '1'}} >
</span>
</li>
<li class="payment__item">Total:
<span>${{ number_format($payment_total + $shipping_cost, 2, '.', '')}} </span>
</li>
#else
<li class="payment__item">Total: <span>${{ number_format($payment_total + 10, 2, '.', '')}} </span>
</li>
#endif
And in my controller I have this for my public function:
public function showPayment() {
$cart = Session::get('cart');
$payment_info = Session::get('payment_info');
if($payment_info['status'] == 'on_hold' ) {
$total_weight = $cart->totalWeight;
// $shipping_cost = $cart->totalPrice + 5;
$sales_tax = $cart->totalPrice * .085 ;
$payment_total = $cart->totalPrice + $sales_tax;
return view('cart.payments', ['payment_info' => $payment_info, 'cartItems' => $cart, 'sales_tax' => $sales_tax, 'shipping_cost' => $shipping_cost, 'total_weight'=>$total_weight, 'payment_total' => $payment_total]);
}else{
return redirect()->route("home");
}
}
Any help is much appreciated.
Edit here is the data that is being passed
Use javascript to check if the checkbox is checked. If it is, then add the priority shipping cost to the total
var input = document.querySelector('input[type=checkbox]');
function check() {
var a = input.checked ? "{{$payment_info['price'] + number_format($sales_tax, 2, '.', '') + 10 }}" : "{{$payment_info['price'] + number_format($sales_tax, 2, '.', '') + 5 }} ";
document.getElementById('total').innerHTML = '$ ' + a;
}
input.onchange = check;
check();

PHPExcel attempting to read Excel file using ajax() call is failing

I am attempting to read an Excel File using PHPExcel Lib through an ajax call. However, the read attempt is causing an error of PHPExcel_Reader_Exception: Could not open for reading! File does not exist.
My index.php is as follows:-
<?php
ob_start();
ini_set("xdebug.var_display_max_children", -1);
ini_set("xdebug.var_display_max_data", -1);
ini_set("xdebug.var_display_max_depth", -1);
session_start();
if ( isset($_POST['label']) ) {
var_dump($_POST['label']);
}
?>
<!doctype html>
<html lang="en">
<head>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<script>
var label;
function checkfile(sender) {
var validExts = new Array(".xlsx", ".xls");
var fileExt = sender;
fileExt = fileExt.substring(fileExt.lastIndexOf('.'));
if (validExts.indexOf(fileExt) < 0) {
alert("Invalid file selected, valid files are of " +
validExts.toString() + " types.");
return false;
} else return true;
}
$(function() {
$(document).on('change', ':file', function() {
var input = $(this),
numFiles = input.get(0).files ? input.get(0).files.length : 1,
label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
input.trigger('fileselect', [numFiles, label]);
});
$(document).ready( function() {
$(':file').on('fileselect', function(event, numFiles, label) {
if(checkfile(label)== true){
var input = $(this).parents('.input-group').find(':text'),
log = label;
if(input.length) {
input.val(log);
} else {
// if(log) alert(log);
}
}
$.ajax({
//url:"../uploadxlsx/readxlsx.php",
url:"uploadxlsx/readxlsx.php",
method:"POST",
data:{label:label },
success:function(data){
$('#sheetnames').html(data);
}
});
});
});
});
</script>
</head>
<body>
<br>
<br>
<br>
<div class="container">
<table>
<thead>
<div class="input-group">
<label class="input-group-btn">
<span class="btn btn-primary">
Browse <input type="file" id="uploadfile" name="uploadfile" style="display: none;" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel">
</span>
</label>
<input type="text" class="form-control" readonly="">
</div>
</thead>
</table>
</div>
<div class="input-group" name='sheetnames' id='sheetnames'>
</div>
</body>
</html>
The ajax called php file readxlxs.php is as follows:-
<?php
ini_set("xdebug.var_display_max_children", -1);
ini_set("xdebug.var_display_max_data", -1);
ini_set("xdebug.var_display_max_depth", -1);
ob_start();
include_once $_SERVER['DOCUMENT_ROOT'] . '/CommandWks/phpAssets/Classes/PHPExcel.php';
$exceldata = array();
//$inputfilename = $_POST['label'];
$inputfilename = basename($_FILES['fileName']);
var_dump($inputfilename);
$inputfiletype = PHPExcel_IOFactory::identify($inputfilename);
$objReader = PHPExcel_IOFactory::createReader($inputfiletype);
$objPHPExcel = $objReader->load($inputfilename);
$excelReader = PHPExcel_IOFactory::createReaderForFile($inputfiletype);
$excelObj = $excelReader->load($inputfiletype);
$worksheet = $excelObj->getSheet(0);
$lastRow = $worksheet->getHighestRow();
var_dump($lastRow);
ob_end_flush();
?>
A screenshot of the error displayed is this
Where is the error? Or is it that PHPExcel cannot be used with ajax?
general advice
you could use browser debug console (F12 if chrome) to see if file actually got upload
you could var_dump($_FILES) to see actually what server got
this has nothing to do with begin ajax vs PHPExcel, I think you got it wrong at the basic level of how to handle form data in PHP
and on your question, since your file input is like this
<input type="file" id="uploadfile" name="uploadfile"
variable name must be
$_FILES["uploadfile"]
and "name" is just name, for actual file you'll have to use
$_FILES["uploadfile"]["tmp_name"]
read this for more info on $_FILES array structure
Array
(
[file1] => Array
(
[name] => MyFile.txt (comes from the browser, so treat as tainted)
[type] => text/plain (not sure where it gets this from - assume the browser, so treat as tainted)
[tmp_name] => /tmp/php/php1h4j1o (could be anywhere on your system, depending on your config settings, but the user has no control, so this isn't tainted)
[error] => UPLOAD_ERR_OK (= 0)
[size] => 123 (the size in bytes)
)
)

jquery isotope - sort, layout AND multiple filters

I'm trying to create a page with sorting, layout buttons and multiple filters. The isotope homepage is a good example, but there's only one filter there. Using that page I can't figure out how to add more filters that will work together (i.e. colour and size, working together, not one at a time). Below is the code... How do I add another filter?
<div class="option-combo">
<h2>Filter:</h2>
<ul id="filter" class="option-set clearfix" data-option-key="filter">
<li>show all</li>
<li>elements</li>
<li>features</li>
<li>examples</li>
</ul>
</div>
<div class="option-combo">
<h2>Sort:</h2>
<ul id="sort" class="option-set clearfix" data-option-key="sortBy">
<li><a href="#sortBy=original-order" data-option-value="original-order" data>original-order</a></li>
<li>name</li>
<li>year</li>
<li>size</li>
<li>random</li>
</ul>
</div>
<div class="option-combo">
<h2>Layout: </h2>
<ul id="layouts" class="option-set clearfix" data-option-key="layoutMode">
<li>masonry</li>
<li>fitRows</li>
<li>straightDown</li>
</ul>
</div>
And this is the javascript:
$(function(){
var $container = $('#container');
$container.isotope({
masonry: {
columnWidth: 70
},
sortBy: 'year',
sortAscending : false,
getSortData: {
name : function ( $elem ) {
return $elem.find('.name').text();
},
size : function ( $elem ) {
return parseInt( $elem.find('.Size').text().replace( /,/g, ''), 10 );
},
year : function ( $elem ) {
return parseInt( $elem.find('.year').text().replace( /,/g, ''), 10 );
}
}
});
var $optionSets = $('#options .option-set'),
$optionLinks = $optionSets.find('a');
$optionLinks.click(function(){
var $this = $(this);
// don't proceed if already selected
if ( $this.hasClass('selected') ) {
return false;
}
var $optionSet = $this.parents('.option-set');
$optionSet.find('.selected').removeClass('selected');
$this.addClass('selected');
// make option object dynamically, i.e. { filter: '.my-filter-class' }
var options = {},
key = $optionSet.attr('data-option-key'),
value = $this.attr('data-option-value');
// parse 'false' as false boolean
value = value === 'false' ? false : value;
options[ key ] = value;
if ( key === 'layoutMode' && typeof changeLayoutMode === 'function' ) {
// changes in layout modes need extra logic
changeLayoutMode( $this, options )
} else {
// otherwise, apply new options
$container.isotope( options );
}
return false;
});
});
Multiple filters as I understand means selection elements that share multiple properties.
So for example if we have the following isotope items
<div class="isotope-item green big"></div>
<div class="isotope-item green small"></div>
<div class="isotope-item red big"></div>
<div class="isotope-item red small"></div>
<div class="isotope-item yellow big"></div>
If you want to as a filter all the elements that are
red AND big
red OR big
then you can use with the same JavaScript that you have :
<h2>Filter:</h2>
<ul id="filter" class="option-set clearfix" data-option-key="filter">
<li><a data-option-value="*" class="selected">Show All</a></li>
<li><a data-option-value=".red">Show Red Elements</a></li>
<li><a data-option-value=".big">Show Big Elements</a></li>
<li><a data-option-value=".red, big">Show Elements Red OR Big</a></li>
<li><a data-option-value=".red.big">Show Elements Red AND Big</a></li>
</ul>
The filter works with a simple jQuery selector. Everything that matches the selection is shown, the rest is hidden.
I tried to explain my approach on this question here.
Basically the idea is to look for a restrictive AND condition using the isotope function properly in your onclick event.

Resources