django-admin-bootstrapped messing with DateField, TimeField and PointField - javascript

I've just added django-admin-bootstrapped to my project. Almost everything is fine.
Actually there are two little bug whitch i'm wondering how to resolve.
The first one is about DateField and TimeField : There is no date/time picker when i'm under django-admin-bootstrapped. When i check the source code, there is no generated source code about the two picker. When i deactivate django-admin-bootstrapped, here is what is missing :
Next to the DateField :
<span class="datetimeshortcuts">
Today |
<a href="javascript:DateTimeShortcuts.openCalendar(0);"
id="calendarlink0"><img src="/static/admin/img/icon_calendar.gif" alt="Calendar">
</a></span>
Next to the TimeField :
<span class="datetimeshortcuts">
Now |
<a href="javascript:DateTimeShortcuts.openClock(1);"
id="clocklink1"><img src="/static/admin/img/icon_clock.gif" alt="Clock">
</a></span>
The second one is about a PointField (i'm working with postGis), without django-admin-bootstrapped, my field is fine, but when it's bootstrapped, i have an error onto OpenLayer.js :
OpenLayers.js:679 Uncaught TypeError: Cannot read property 'w' of null
So, two questions (using django 1.8 and django-admin-bootstrapped):
1- How to recover a date/time picker in the admin interface ?
2- How to recover my PointField map picker in the admin interface ?
Thank's all of you. (Here the same issue (1) on github : https://github.com/django-admin-bootstrapped/django-admin-bootstrapped/issues/168 but there is only external workarround (and i prefer a nativ one))
EDIT : From my sitepackage : ./django/contrib/gis/admin/options.py
I've directly changed the line who call OpenLayer.js to OpenLayer.debug.js to provide you more information.
In OpenLayer.debug.js line 40008 is the source of the error :
setMap: function(map) {
OpenLayers.Layer.prototype.setMap.apply(this, arguments);
if (!this.renderer) {
this.map.removeLayer(this);
} else {
this.renderer.map = this.map;
var newSize = this.map.getSize();
40008-> newSize.w = newSize.w * this.ratio;
newSize.h = newSize.h * this.ratio;
this.renderer.setSize(newSize);
}
},
Here the entire JS traceback on OpenLayer.debug.js + index of GeoDjango:
Uncaught TypeError: Cannot read property 'w' of null ==> OpenLayers.debug.js:40008
newSize.w = newSize.w * this.ratio;
OpenLayers.Layer.Vector.OpenLayers.Class.setMap ==> OpenLayers.debug.js:8349
layer.setMap(this);
OpenLayers.Map.OpenLayers.Class.addLayer ==> (index):614
geodjango_gps_point.map.addLayer(geodjango_gps_point.layers.vector);
geodjango_gps_point.init ==> (index):677 (anonymous function)
<script type="text/javascript">geodjango_gps_point.init();</script>

Two problems were describ and sorry for the poor lisibility. So here some answers :
1 - The DateField and Timefield seems to be issued and this will be fix :
Fix 168 (last update 3 days ago)
2 - My PointField show up correctly after adding this options to settings.py :
DAB_FIELD_RENDERER = 'django_admin_bootstrapped.renderers.BootstrapFieldRenderer'
Thank's all

Related

SuiteScript2.0 Please Add Value To Amount

I have a suitelet that is creating an order. Most times this works but sometimes, maybe 1 in 50 it fails with this error. "Please enter a value for amount."
The error is thrown when sommitting this.
if(orderLine.amount){
log.debug("itemrate", orderLine.itemrate);
salesOrder.setCurrentSublistValue({
sublistId : 'item',
fieldId : 'rate',
value : Number(orderLine.itemrate ? orderLine.itemrate : (orderLine.amount / orderLine.qty))
});
fieldServices.sleep(1000);
log.debug("Amount", orderLine.amount);
salesOrder.setCurrentSublistValue({
sublistId : 'item',
fieldId : 'amount',
value : Number(orderLine.amount)
});
}
The logs on a fail execution reads
2 View Debug Amount 26/05/2020 11:21 AM -System- 118.0909090909091
3 View Debug itemrate 26/05/2020 11:21 AM -System- 118.0909
So the amount is getting set with an amount but when I try to commit the line it doesn't work 100% of the time.
So here was the problem. I assumed the logging was on the line that I posted but it turned out it was trying to add another line with the amount of 0. JavaScript being JavaScript saw 0 as false in
if(orderLine.amount)
so the amount was never added to the line. I changed this if statement to read
if(orderLine.amount || orderLine.amount == 0)
This solved the problem.

Editstrap - internal js error

Using Edistrap, once "tag" type is selected it throws error saying "uncaught type error, tagsInput.tagsinput is not a function". Traced code:
var tagsInput = html.find("input");
tagsInput.tagsinput({
tagClass : function(item) {
return 'label label-info';
}
});
html.removeClass("input-group-sm");
html.find(".bootstrap-tagsinput").addClass("form-control");
html.find(".validate").click(function() {
var allTags = tagsInput.tagsinput('items');
_this.submitEditable(span, allTags.join(_this.options.multipleSeparator), allTags);
});
I ain't no js programmer so I am asking if this is something I can fix easily.
Solution by Amy:
Include bootstrap-tagsinput.css & bootstrap-tagsinput.js
from https://github.com/bootstrap-tagsinput/bootstrap-tagsinput/tree/master/src
Note that .css file needs to be edited in terms of colors to work with Editstrap.

Grails RemoteFunction creates bad javascript

I am taking over a project from an engineer that left my company, and am having to quickly come up to speed on Grails, so if this is a noob question, well, I'm a noob.
In one of one of my GSP files, I've got a remoteFunction call in the middle of a javaScript function:
function fnCreateEntitiesPerForceChart() {
var interval = $("#entitiesPerForceTimeIntervalSelect").val();
var url = '${createLink(controller: 'federation', action: 'createEntitiesPerForceChart')}?interval='+escape(interval);
$("#entitiesPerForceChart").attr("src", url);
${remoteFunction(controller: 'federation',
action: 'getEntitiesPerForceTable',
params: '\'interval=\'+interval',
onSuccess: 'fnUpdateEntitiesPerForceTable(data,textStatus)')};
}
That remoteFunction call is being sent to the client as:
try{DojoGrailsSpinner.show();}catch(e){} dojo.xhr('Get',{content:{'interval='+interval}, preventCache:true, url:'/FederationReporter/federation/getEntitiesPerForceTable', load:function(response){ fnUpdateEntitiesPerForceTable(data,textStatus); }, handle:function(response,ioargs){try{DojoGrailsSpinner.hide();}catch(e){} }, error:function(error,ioargs){try{DojoGrailsSpinner.hide();}catch(e){} } });;
Which is causing a error:
SyntaxError: missing : after property id
...){} dojo.xhr('Get',{content:{'interval='+interval}, preventCache:true, url:'/Fed...
federation (line 400, col 60) (which is the bolded '+' before the second 'interval'
What am I missing?
Dojo content should be a key-value pair.
{content:{'interval': interval}

Twitter like "x new tweets" with .arte or .ajax?

I've found this great example to implement a twitter like "x new tweets" http://blog.hycus.com/2011/03/14/realtime-updates-like-twitter-using-phpmysqljquery/
In this example the .arte jQuery plug-in is used. However I think it can be done just as the same with .ajax and I've coded as:
$.ajax({
url:'async.php? main='+$('.boxOfMainPage:first').attr('id'),
success:function(results)
{
if(results!='')
{
if(results.indexOf('boxOfMainPage')>=0)
$('#tweetEveryone').prepend(results);
else
$('#newTweet').html("<center><a href=''>I found "+results+" new tweets</a></center>").show();
}
}
});
This checks the results and loads the result to tweetEveryone. Async.php simply makes a mysql_query and brings the new results. I've actually done exactly the same with the example however when I click the 'new tweet's like it sometimes causes a postback. In the example I haven't experience it. Can it be because of the difference between .arte and .ajax ?
It's nothing about the differences between arte and ajax (in fact and in a short way, arte is ajax that is called with an interval, trying to do something like "long polling")
So, u have a link without href value, this must "reload" ur page, ie, it will perform a GET request to the actual URL in window.location. A postback performs a POST request, this is really happening?
--- edited ---
If you wanna to do the same effect from twitter, it's simple.. In async.php, instead u write an link element that shows how many tweets has after the old state, make this page write a JSON object with all tweets, then, ur ajax function must get this JSON and convert it into a JS object. With this object, u'll be able to count how many updates u have to show and exactly which are they.
So, ur function could be like this (assuming that "#boxOfMainPage" is ur tweets container):
$.ajax({
url : 'async.php?main='+$('.boxOfMainPage:first').attr('id'),
success : function (tweets) {
window.NEW_TWEETS = tweets;
if ( NEW_TWEETS && NEW_TWEETS.length ) {
$('#newTweet').html("<center><a href='#' onclick='showNewTweets()'>I found "+NEW_TWEETS.length+" new tweets</a></center>").show();
}
}
});
The showNewTweets functions will be:
function showNewTweets() {
if ( window.NEW_TWEETS && NEW_TWEETS.length ) {
$('#newTweet').hide().html("");
for ( tweet in NEW_TWEETS ) {
$("#boxOfMainPage").prepend(buildTweetHTML(tweet));
}
}
}
And buildTweetHTML:
function buildTweetHTML(tweet) {
var $tweetElm = $("<div class='tweet'>");
$tweetElm.append("<h2>"+tweet.user+" said:</h2>");
$tweetElm.append("<p>"+tweet.content+"</p>");
$tweetElm.append("<p class='time'>"+tweet.time+"</p>");
return $tweetElm;
}
Finally, async.php should write JSON object like this:
[
{ user : 'Rafael', content : 'The content from tweet', time : 'X time ago' },
{ user : 'George', content : 'The content from tweet', time : 'Y time ago' }
{ user : 'Jack', content : 'The content from tweet', time : 'H time ago' }
]

Javascript Error,Escaping Problem,Grid not working,Error on Firebug

we are just started with Sigma Grid ,and it is awesome in its functionality when we compared to other Grids.
But i encountered some problem with Sigma Grid ,or may be with javascript.
I dont know whether the problem is with Grid or with my code.
I have a table with 3 fields namely MailID,MailName,MailData.
MailID is int ,MailName and MailData contains HTML content and it save as string in database.
When i load the Grid,i have some problems.
Problem 1 :
As i said above the Maildata contain html content,the following image is just a example with <*b> ,u can see that the HTML is automatically rendering on the grid itself ,i need the exact string.
please check the following image.
Problem 2 :
as u can see i have links on the grid,for edit,send,delete but on one filed its damaged.[check the image below ]
the code i used to render links is following .
{id: 'mailid' , header: "Action", width :120 , resizable : false, sortable : false , printable : false ,
renderer : function(value ,record,columnObj,grid,colNo,rowNo){
var no= record[columnObj.fieldIndex];
var cod = (record['maildata']);
return 'Edit | Delete';
Problem 3 :
The third value of MailData is 5 and it is integer ,when i alert the value its shows it correctly.
check the following image.
But when i alert the second value of maildata it giving error ,the second value of MailData is "hai newuser" ,it showing the following error on firebug.
missing ) after argument list
alert(hai newuser)
check the image below.
But when i alert 9th value of MailData it run correctly ,the content is <b>poy</b> ,this one is also save as string,but the grid automatically BOLD [which i dnt like].Check the image below.
also there are some others the 7the value contain ;".: etc ,also /b ,when i alert the data it showing the following error,
unexpected end of XML source
alert(<b>jjfdslkdjflsdnfsldfnf
dsOptions and ColOptions are following .
var dsOption= {
fields :[
{name : 'mailid' },
{name : 'mailname',type:"text" },
{name : 'maildata',type:"text" }
],
recordType : 'object',
}
function my_renderer(value ,record,columnObj,grid,colNo,rowNo)
{
var no= record[columnObj.fieldIndex];
return "<img src=\"./images/flag_" + no.toLowerCase() + ".gif\">";
}
function showalert(no)
{
$(document).ready(function()
{
$.post("http://localhost/power/index.php/power/give",{ name: no}, function(data)
{
//alert("Data Loaded: " + data);
$("#editor").show("fast");
$( '#txtar' ).ckeditor();
$('#txtar' ).val( data.maildata );
//$("#editor").html(data);
},"json"
);
});
}
var colsOption = [
{id: 'mailid' , header: "Mail ID" , width :60},
{id: 'mailname' , header: "Mail Name" , width :160 ,type:"text"},
{id: 'maildata' , header: "Mail Data" , width :190,type:"text" },
{header: "Group" , width :70,
editor : { type :"select" ,options : {'php':'php','asp':'asp'}
,defaultText : 'php' } },
{id: 'mailid' , header: "Action", width :120 , resizable : false, sortable : false , printable : false ,
renderer : function(value ,record,columnObj,grid,colNo,rowNo){
var no= record[columnObj.fieldIndex];
var cod = (record['maildata']);
return 'Edit | Delete';
} }
];
I am littlebit new in Javascript and Sigmagrid,i think that i am doing something worst with codes,pls help me to success.
Thank you.
Note : i posted the same Question on Sigma Grid Forum too,i think that it is not a problem.
Problem 2
The string cod contains a >
Problem 3
The string hai newuser needs to be contained in " or ' or it is considered a variable name
Basically you have to decide -- are you going to validate the html or not. If you don't validate the HTML then html errors in the data will show as errors on your page. You could also HTML escape the html so you will see the HTML codes -- this is probably the best plan.
Other sites use (like this one) use markdown -- this is easier to validate -- then they generate the actual HTML before display.
In addition you are having problems with the alert. Alert displays strings not HTML so you will see what you are seeing -- different results than expected depending on the HTML.
I would take a step back and ask yourself -- what is the type of the data, how am I going to display it. How am I going to validate that if it is HTML it is valid.
There are the problems you need to address -- your examples all stem from this problem.

Categories

Resources