I want to make a countdown for my website and I can't do it.
Please help me
I try with a tag "for" but you need the "while" loop which has no tag in django
In order to create a countdown that is visible for visitors in your website, you will actually need Javascript code in your HTML template.
Here is an example function that would help you:
<div id="countdown"></div>
<script type="text/javascript">
var count={{countdown_end_time}};
var counter=setInterval(timer, 1000);
function timer() {
count=count-1;
if (count <= 0) {
clearInterval(counter);
$('div #countdown').html('Timeout reached');
return;
}
min = Math.floor(count/60);
secs = (count % 60)
$('div #countdown').html('You have ' + (min < 10 ? '0'+min : min) + ':' + (secs < 10 ? '0'+secs : secs) + ' minutes left')
}
</script>
Related
I'm trying to make a script that will find the width of an item and check if the selected item width is the same and then show an alert.
For some reason my if condition is not working even when all the conditions are met.
Here is my code:
var doc = app.activeDocument;
function mm(n) {return n / 2.83464566929134;}
function pt(n) {return n * 2.83464566929134;}
//=====================
// Calculate Prisa
//=====================
var prisa = doc.pathItems.getByName("prisa");
var prisawidth = mm(prisa.geometricBounds[2]-prisa.geometricBounds[0]);
//=========================
// Calculate Selection
//=========================
var sel = doc.selection[0];
var selwidth = mm(sel.geometricBounds[2]-sel.geometricBounds[0]);
if (selwidth == prisawidth) {alert("Same Width");}
You can try this:
if (Math.abs(selwidth - prisawidth) < .01) alert("About the same width");
I think the problem has to do with rounding of the numbers. Say, you can see '2 mm' and '2 mm', but actually there are '2.00001 mm' and '2.00002 mm' or something like this. So it's need either to round the fugures before compairing or check if the diffference is less than some minimal value.
How can I sum fields on each row in a tabular form in APEX 4.2 to get a total for that row before I submit the page in order to do page validation?
For example if the first row has 6 in field a and 6 in field b the total for the first row should be 12 and on the second row if field b is 5 and field c is 5 the total for the second row should be 10.
So I want to get totals based on rows not column. Is that possible?
Yes, its possible. If you know javascript/jquery, you'll get along well with my solution. This is what you have to do:
get the name attribute(using inspect element of your browser) of the field you want to sum up. Names of fields in oracle apex usually goes like 'f01' or 'f02' and so on. Once you get the fields, create a javascript function or you can use this one if you like:
function sumUpRows(columnforsum,itemstobeadded){
var numofcols = arguments.length;
var numofrows = $("[name=" + arguments[0] + "]").length;
var summ = 0;
for(x=0;x<numofrows;x++){
for(i=1;i<numofcols;i++){
summ = summ + Number($("[name=" + arguments[i] + "]").eq(x).val());
}
$("[name=" + columnforsum + "]").eq(x).val(summ);
}
}
Put function above in "function and global variable declaration" part of your page. Then create a "before page submit" dynamic action. Set its action to "execute javascript" then put this line of code:
sumUpRows("nameoffieldwheresumwillbeassigned","nameofitem1","nameofitem2","nameofitem3");
Here's a sample :
sumUpRows("f04","f01","f02","f03");
For your question in the comment section, the answer is yes. To get the sum of a row automatically as you fill up the boxes on that row, you can use this function:
function sumUpRowsAsYouGo(whatelement){
var numofrows=$("[name=f01]").length;
var summ = 0;
for(i=0;i<numofrows;i++){
if($(whatelement).attr("id") == $("[name=" + $(whatelement).attr("name") + "]").eq(i).attr("id")){
for(a=1;a<(arguments.length-1);a++){
summ += Number($("[name="+ arguments[a] + "]").eq(i).val());
}
$("[name="+ arguments[arguments.length-1] + "]").eq(i).val(summ);
break;
}
}
}
you can use this function like this(put these lines in the "Execute on Page load" and "after refresh" dynamic action of your tabular form region):
$("[name=f01]").change(function(){
sumUpRowsAsYouGo(this,"f01","f02","f03","f04");
}
);
$("[name=f02]").change(function(){
sumUpRowsAsYouGo(this,"f01","f02","f03","f04");
}
);
$("[name=f03]").change(function(){
sumUpRowsAsYouGo(this,"f01","f02","f03","f04");
}
);
I'm trying to be real fancy with angular inputs by using both ng-pattern and ng-model parsing together. The regex I put in ng-pattern works fine on regex101.com, and even logging it in my app it works great. When using it in ng-pattern however, its saying my input is invalid though when it should not be. I'm wondering when ng-pattern does its thing in relation to when ngModel.$parsers/ngModel.$formatters are doing their thing, because i could see that causing it to fail. Here's some code:
Here's the ngModel parsing directive:
UI.directive('formatSeconds', function() {
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, element, attrs, ngModel) {
var padZero = function (num, size) {
return ('00' + num).substr(-size);
};
var formatSeconds = function (seconds) {
var min = Math.floor(seconds / 60);
var sec = Math.floor(seconds % 60);
var ms = Math.round(((seconds % 60) - sec) * 1000);
return min + ':' + padZero(sec, 2) + ':' + padZero(ms, 3);
};
var parseTime = function (time) {
time = time.split(':');
var min = parseInt(time[0] || 0);
var sec = parseInt(time[1] || 0);
var ms = parseInt(time[2] || 0);
return min * 60 + sec + (ms / 1000);
};
ngModel.$parsers.push(parseTime);
ngModel.$formatters.push(formatSeconds);
}
};
});
Here's my regex in my controller:
$scope.timeRegex = /^([0-9]+)?\:([0-5][0-9])\:?([0-9]{3})?$/;
And here's the relevant part of my view:
<tbody ng-form name="syncForm">
<tr class="timing-entry" ng-repeat="entry in scenario.syncManifest">
<td>
<input type="text" ng-attr-name="{{'time' + $index}}" required ng-model="entry.time" format-seconds ng-pattern="timeRegex" />
</td>
</tr>
</tbody>
The time in entry is in seconds, so the formatter puts it in 0:00:000 format. Then I hoped the ng-pattern would kick in and say yes! valid! But I'm wondering if it is running when the time property is still in 0.000 format before parsing.
Angular validation is performed upon the ng-model value, that is to say:
When a value is inputted into the view, the $parsers will run and the inputted value will be transformed into how you want it stored in the ng-model. In this case, thats a number representing the number of seconds. Then the ng-pattern will work on that value - if it passes validation, ng-model will be set.
When the value is set from the controller, the ng-pattern will go to work on that raw ng-model value. I believe the $formatters will run and the formatted $viewValue will be sent to the view regardless of the validation result.
Either way - in your example, ng-pattern will be working on the integer value of seconds, not the formatted value displayed in the control.
Been trying to use KendoUI templates and MVVM to create a menu that resembles a table of contents like so:
Lesson 1:
- Slide 1
- Slide 2
Lesson 2:
- Slide 1
and so on. I have the following data that I've created a kendo.observable with:
var CourseData = kendo.observable({
name: 'HTML Test Course',
lessons: [
{ // Lesson 1
name: 'Lesson 1',
slides: [
{ // Slide 1.1
name: 'Animation',
type: 'CreateJS',
cctext: '<p>...</p>',
}
]
}
]
});
Before discovering KendoUI I built the menu using plain JavaScript and for the given data it turns out like this:
<ul>
<li>
<span>Lesson 1</span>
<ul>
<li onclick="Shell.GoToSlide(1, 1)" class="unlocked"><!-- 0 = locked, 1 = unlocked, 2 = viewed, 3 = completed -->
<span>Animation</span>
</li>
</ul>
</li>
</ul>
The two pieces of this puzzle that I am having trouble expressing together are the progress (noted by the class) and the click event. Progress is stored in either a jagged array right in CourseData (like CourseData.progress = [[3]], so CourseData.progress[lesson][slide] will give the progress of that slide.) or if it would better solve this conundrum I would consider moving it to each slide object (like CourseData.lessons[lesson].slides[slide].progress). The click event calls a navigation function written elsewhere that brings up the slides using their lesson and slide number (base 1) and is not added to the item if progress is locked.
With templates, I can do something like the following:
<script type="text/x-kendo-template" id="coursemap-template">
# for (var l = 0; l < lessons.length; l++) { #
<li>
<span>#: lessons[l].name #</span>
<ul>
# for (var s = 0; s < lessons[l].slides.length; s++) { #
<li onclick="Shell.GoToSlide(#: s + 1 #, #: l + 1 #)"><span>#: lessons[l].slides[s].name #</span></li>
# } #
</ul>
</li>
# } #
</script>
To get easy access to the indices of each lesson and slide, but it won't let me bind to a specific element in an array like: data-bind="attr: { class: progress[l][s] }" when Kendo evaluates this binding later it does not know what l and s are, nor can I think of an elegant way to translate the numbers into the appropriate strings. If I use class="#: ['locked','unlocked','viewed','completed'][progress[l][s]] #" it works but does not automatically update when the progress changed. If I used nested templates and made progress a property of slide I could bind to it no problem but then I wouldn't know how to get the lesson and slide indices for the click event without tons of indexOf calls or parent().parent() shenanigans. Thoughts?
Not the ideal solution, but this question has enough views that I suppose I should provide the code I used as a workaround:
View:
<ul id="coursemap"></ul>
ViewModel:
(function () {
for (var l = 0; l < CourseData.lessons.length; l++) {
var lessonItem = document.createElement('li');
$(lessonItem).attr('data-bind', 'html: lessons[' + l + '].name');
$('#coursemap').append(lessonItem);
var slides = document.createElement('ul');
for (var s = 0; s < CourseData.lessons[l].slides.length; s++) {
var slideItem = document.createElement('li');
$(slideItem).attr('data-bind', 'html: lessons[' + l + '].slides[' + s + '].name, attr: { data-progress: progress[' + l + '][' + s + '] }');
(function (lesson, slide) {
$(slideItem).click(function () {
// If the target slide is not locked, navigate.
if ($(this).attr('data-progress') != 0) {
Shell.GoToSlide(slide, lesson);
ExtensionManager.AutoHide();
}
})
})(l + 1, s + 1);
$(slides).append(slideItem);
}
$('#coursemap').append(slides);
}
kendo.bind($('#coursemap'), CourseData);
})();
I am using google charts API specifically pie chart in my code i want to show percentage which is displayed inside chart to the legends also
How can i display 29.2% sleep in legend?
You can do this two ways; either set the formatted values of the labels in the DataTable to include the percents, eg:
// assume sleep is row 4, "sleepPercent" is the percent for sleep
data.setFormattedValue(4, 0, data.getValue(4, 0) + ' (' + (sleepPercent * 100).toFixed(1) + '%)');
or you can set the legend.position option to "labeled", which changes the way the legend is drawn, but adds the percents to the labels:
legend: {
position: 'labeled'
}
see an example here: http://jsfiddle.net/asgallant/Su6TX/
Try this for all values:
var total = 0;
for (var i = 0; i < data.getNumberOfRows(); i++) {
total = total + data.getValue(i, 1);
}
for (var i = 0; i < data.getNumberOfRows(); i++) {
var label = data.getValue(i, 0);
var val = data.getValue(i, 1) ;
var percentual = ((val / total) * 100).toFixed(1);
data.setFormattedValue(i, 0, label + '- '+val +' ('+ percentual + '%)');
}