I have an issue with Breezejs (1.4.2) q (0.9.7)
I want to add a computed property for an entity.
var doctorInitializer = function (doctor) {
doctor.FullName = ko.computed(function () {
return doctor.FirstName() + " " + doctor.MiddleName() + " " + doctor.LastName() + " " + doctor.SurName();
});
};
var doctorName = '/breeze/polyclinic',
doctorManager = new breeze.EntityManager(doctorName);
var store = doctorManager.metadataStore;
store.registerEntityTypeCtor("Doctor", null, doctorInitializer);
i try adding a knockout computed to the constructor
var doctor = function () {
self.FullName = ko.computed( {
read: function() {
return self.FirstName + " " + self.MiddleName + " " + self.LastName + " " + self.SurName;
},
deferEvaluation: true
});
};
store.registerEntityTypeCtor("Doctor", doctorInitializer);
in both cases only work if i remove the parenthesis but MiddleName and SurName is not required and instead of empty string i got null
this is the error i have http://screencast.com/t/bP9Xnmf9Jm
UPDATE
I try adding the error on console log and follow your example and i have the same error is not a function http://screencast.com/t/bQTyV8XGD0Pk
doctor.FullName = ko.computed(function () {
var fullName = "";
fullName += doctor.FirstName();
if (doctor.FirstName()) {
fullName += ' ' + doctor.FirstName();
}
fullName += ' ' + doctor.LastName();
if (doctor.SurName()) {
fullName += ' ' + doctor.SurName();
}
return fullName;
});
var query = breeze.EntityQuery.from("Doctors").orderBy("Id")
doctorManager.executeQuery(query)
.then(function (data) {
self.doctors.removeAll();
self.doctors(data.results);
})
.fail(function(error) {
console.log(error);
});
I hope someone can help me
The error you are seeing in the screenshot is because your query is throwing an error that you are not handling. Attach a .fail(failFunction) on the end of your entityQuery.
You can't call doctor.Surname() if there is no Surname function that is attached. Calling doctor.Surname just returns a function that doesn't give you a value.
Odds are, you don't 100% get why it's not working because you don't understand how Knockout works. You probably don't yet understand the meaning of what I am describing above either. You need to understand how Knockout works first, then try to learn Breeze.
If you want to just make it work without understand how or why put this in there and continue on. This assumes that there is a property returned called MiddleName and SurName that are just empty.
doctor.FullName = ko.computed(function () {
var fullName = "";
fullName += doctor.FirstName();
if (doctor.MiddleName()) { fullName += ' ' + doctor.MiddleName(); }
fullName += ' ' + doctor.LastName();
if (doctor.SurName()) { fullName += ' ' + doctor.SurName(); }
return fullName
});
Related
I have set a 'tooltip' at columnDefs as below,
var columnDefs = [{
headerName: "City",
field: "city",
cellRenderer: function(params) {
return '<span title="'+params.value+'">'+params.value+'</span>';
},
editable: true
}
This tool tip is rendered properly on hover over the cells with the value in the cell.
Now I am also capturing the old and new values after a cell edit in onCellValueChanged() event handler as below,
onCellValueChanged: function(params) {
if (params.oldValue !== params.newValue) {
// Send the values to the tool tip
}
}
Is it possible to update my tool tip with the values captured in the onCellValueChanged() handler ? I mean, passing the params.oldValue and params.newValue() somehow to the 'tooltip' which is on my cellRenderer.
This issue is fixed, this demo updates tool tips when change occurs.
var oldValue = params.oldValue;
var newValue = params.newValue;
var recordKey = params.data.key;
var columnField = params.colDef.field;
if (!_.isEqual(oldValue, newValue)) {
if (!cellMetadata[recordKey]) {
cellMetadata[recordKey] = {};
}
if (!cellMetadata[recordKey][columnField]) {
cellMetadata[recordKey][columnField] = {};
}
cellMetadata[recordKey][columnField].trackChanges = true;
cellMetadata[recordKey][columnField].tooltip =
columnField.toUpperCase() + ' ' + 'Changed from' + ' ' + oldValue + ' ' + 'to' + ' ' + newValue;
}
I'm trying to create my first extension.
I've found this sample: http://blog.mozilla.org/addons/2009/01/28/how-to-develop-a-firefox-extension/
I need to get some html content on a specific page and write something in the same page, so I modified it and got what I needed (with javascript I added content in the table I want). But to view my content I have to launch the extension from the button on the status bar, while I would like to have it already active in the page as I load/reload it (with a check on the url so to have it working only on that page) but I can't have it automatically.
I tried to add linkTargetFinder.run(); on init area, but... nothing. Moreover the extension as an "autorun" but eve if active, I don0t see any change.
any working sample?
Thanks
Nadia
Here it is the code (I edited just the .js file), I commented a couple of test not working...
var linkTargetFinder = function () {
var prefManager = Components.classes["#mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
return {
init : function () {
gBrowser.addEventListener("load", function () {
var autoRun = prefManager.getBoolPref("extensions.linktargetfinder.autorun");
if (autoRun) {
linkTargetFinder.run();
}
//linkTargetFinder.run(); // doesn't work
}, false);
//linkTargetFinder.run(); // doesn't work
alert("ZZZZZZZZZZZZZZZZZZ"); // doesn't work
},
run : function () {
var head = content.document.getElementsByTagName("head")[0],
style = content.document.getElementById("link-target-finder-style"),
allLinks = content.document.getElementsByTagName("a"),
foundLinks = 0;
if (!style) {
style = content.document.createElement("link");
style.id = "link-target-finder-style";
style.type = "text/css";
style.rel = "stylesheet";
style.href = "chrome://linktargetfinder/skin/skin.css";
head.appendChild(style);
}
for (var i=0, il=allLinks.length; i<il; i++) {
elm = allLinks[i];
if (elm.getAttribute("target")) {
elm.className += ((elm.className.length > 0)? " " : "") + "link-target-finder-selected";
foundLinks++;
}
}
if (foundLinks === 0) {
alert("No links found with a target attribute");
}
else {
//alert("Found " + foundLinks + " links with a target attribute");
}
t = content.document.getElementById("ERSContainer"), // ID of the table
d = t.getElementsByTagName("tr")[1],
r = d.getElementsByTagName("td")[1];
var myMail = "mail: "+r.textContent; //ok scrive nella td
var myName = content.document.getElementById("buyercontactname").value;
var myAddr1 = content.document.getElementById("buyeraddress1").value;
var myAddr2 = content.document.getElementById("buyeraddress2").value;
var myCity = content.document.getElementById("buyercity").value;
var myProv = content.document.getElementById("buyerstateprovince").value;
var myCAP = content.document.getElementById("buyerzip").value;
var elt = content.document.getElementById("buyercountry");
var myCountry = elt.options[elt.selectedIndex].text;
var myTel = content.document.getElementById("dayphone1").value;
var myTag1 = "<tr><td colspan='2'>OK!!!<br />";
var myTag2 = "</td></tr>";
z= t.innerHTML;
t.innerHTML = myTag1 + myMail +
" - "+myName+
myAddr1 + "<br />" +
myAddr2 + "<br />" +
myCity + "<br />" +
myProv + "<br />" +
myCAP + "<br />" +
myCountry + "<br />" +
myTel + "<br />" +
myFlash+
myTag2+z;
}
};
}();
window.addEventListener("load", linkTargetFinder.init, false);
If what you are doing is running a bit of JavaScript on a specific web page, like adding content into a table, maybe you should consider doing a userscript for the Greasemonkey addon instead of a full addon. With this you write your JS for the page and it gets executed each time you browse this specific page.
edit:
Try with this :
init: function () {
gBrowser.addEventListener("load", linkTargetFinder.run, true);
},
...
I bet that the extensions.linktargetfinder.autorun does not exist. So getBoolPref throws an exception and the rest is history.
Change your code to the following
var autoRun;
try {
autoRun = prefManager.getBoolPref("extensions.linktargetfinder.autorun");
} catch(e){
autoRun = false;
}
I use dhtmlx schedule and problem in loading data into scheduler view.
I use databasefirst, so i have a sp to fetch all details to display on scheduler,
public ContentResult Data()
{
var data = new SchedulerAjaxData(
new Entities().tblAppTime.Select(e => new { e.SharedId, e.StartTime, e.Duration}));
return data;}
output from var data (during debugging) :
{[{"SharedId":54,"StartTime":"09/14/2013 10:00","Duration":"09/14/2013 11:20"},{"SharedId":56,"StartTime":"09/14/2013 10:00","Duration":"09/14/2013 10:40"},
{[{"SharedId":10,"StartTime":"09/12/2013 8:50","Duration":"09/12/2013 8:55"},{"SharedId":56,"StartTime":"09/14/2013 10:00","Duration":"09/14/2013 10:40"}]}
still I dont get this binded in scheduler, Please help.
Update:
controller.cs
sched.BeforeInit.Add("customeventbox()");
public ContentResult Data()
{
var scheduler = new DHXScheduler();
scheduler.InitialDate= DateTime.Today ;
var data = new SchedulerAjaxData(new OnlineABEntities().GetAppointmentsDisplay(scheduler.InitialDate).Select(e => new {id= e.ID, e.ResourceID,start_date= e.StartTime,end_date= e.Duration, e.Color,text=""}));
return data;
}
schedscript.js
function customeventbox() {
debugger;
scheduler.attachEvent("onTemplatesReady", function () {
alert("eventbox");
scheduler.templates.event_header = function (start, end, ev) {
alert("eventbox1");
return scheduler.templates.event_date(ev.StartTime) + "-" +
scheduler.templates.event_date(ev.Duration);
};
scheduler.templates.event_text = function (start, end, event) {
alert("eventboxtext");
debugger;
return "<br>" + event.ID + "<br>"+event.Duration +"<br>"+event.StartTime+"<br>"+event.Color+ "sampleready" + "<br>"+ "sampletext" ;
}
});
}
Scheduler have some requirements to the loaded data,
check the article in the docs.
In short, the output data must contain at least four following properties, all case-sensitive - id, start_date, end_date and text
If you fetch data like this, it will be displayed in the scheduler
var data = new SchedulerAjaxData(
new Entities().tblAppTime.Select(e => new { id = e.SharedId, start_date = e.StartTime, end_date = e.Duration, text = ""})
);
Update
on the client data objects will have the same set of properties as objects that has been passed to SchedulerAjaxData. Start and end dates of the event are JS date objects, so they should be converted to string before output.
scheduler.templates.event_text = function (start, end, event) {
var dateToStr = scheduler.date.date_to_str("%H:%i");
return "<br>" + event.id +
"<br>" + dateToStr(event.end_date) +
"<br>" + dateToStr(event.start_date) +
"<br>" + event.Color +
"sampleready" + "<br>"+ "sampletext" ;
}
here is details on date format mask
http://docs.dhtmlx.com/scheduler/settings_format.html
I'm having a problem calling the save method on a domain object. The error is:
groovy.lang.MissingMethodException: No signature of method: static my.awesome.Class.FeedHit.save() is applicable for argument types: () values: []
Possible solutions: save(), save(java.lang.Boolean), save(java.util.Map), wait(), any(), wait(long)
I'm going through an array of FeedHits, updating a flag, and then calling the save method:
void updateFeedHits(Set<FeedHit> list, FeedHitStatus status) {
for (FeedHit feedHit: list) {
feedHit.status = status
try {
feedHit.save()
} catch (Exception ex) {
log.info("unknown exception during update FeedHit", ex)
}
}
}
I've seen other StackOVerflow users have the same problem, but only during tests. This code is in normal release code.
Any help would be appreciated.
EDIT:
Here is the FeedHit object, slightly edited.
class FeedHit {
Feed feed
String title
String body
String url
FeedHitStatus status
String sourceId
String hash
Date publishedDate
Date dateCreated = new Date()
Integer pos = -1
static constraints = {
alert(nullable: true)
title(nullable: true)
body(nullable: true)
url(nullable: true)
status(nullable: true)
sourceId(nullable: true)
hash(nullable: true)
pos(nullable: true)
publishedDate(nullable: true)
dateCreated(nullable: true)
}
static mapping = {
table('alert_hit')
autoTimestamp false
version(false)
alert(column: 'alert_id')
body(sqlType: 'text')
url(sqlType: 'text')
sourceId(column: 'sourceId')
publishedDate(column: 'publishedDate')
dateCreated(column: 'dateCreated')
}
/**
* Generates a hash from title, body and url.
*/
public AlertHit generateHash() {
StringBuffer sb = new StringBuffer();
if (this.title != null) {
sb.append(this.title);
}
if (this.body != null) {
sb.append(this.body);
}
if (this.url != null) {
sb.append(this.url);
}
if (this.publishedDate != null) {
sb.append(this.publishedDate.getTime());
}
if (sb.length() > 0) {
hash = Md5Hash.hash(sb.toString());
}
this
}
#Override
public String toString() {
return "AlertHit{" +
"id=" + id +
", alert=" + alert +
", title='" + title + '\'' +
", body='" + body + '\'' +
", url='" + url + '\'' +
", status=" + status +
", sourceId='" + sourceId + '\'' +
", hash='" + hash + '\'' +
", publishedDate=" + publishedDate +
", dateCreated=" + dateCreated +
", pos=" + pos +
", version=" + version +
'}';
}
}
You need to annotate GORM functions, if you want to use domain class outside grails. See http://www.rimerosolutions.com/using-gorm-standalone-outside-grails/
I would recommend you to use another way than native threads. Try: Quartz-Plugin
I have a Google Calendar for a school website I'm working on and am using the Google API to display the next five calendar events. One problem is that the time displays on a 24 hour clock instead of AM and PM, but that's not my main problem. The main problem is that while the events display the correct time on the website, when you click on the event to view it in the calendar event view, it will only display GMT time instead of Eastern Time. While logged into the Google account, the events display the right time zone, but whenever you view it while not logged in, it defaults to GMT.
I have tried changing it to another time zone and change it back, didn't fix it.
I also made sure all settings in both the calendar and the account were set to Eastern time zone, at least everywhere I could find it.
I've seen a lot of people with similar problems on Google sites using the ical or other feeds, but I haven't seen anyone with the problem using a code similar to mine.
The website is live: http://fletcheracademy.com. And here is the main javascript code that pulls it.
There's probably some details I'm missing, let me know if there's anything else you need to know. Thanks so much!
<script type="text/javascript">
google.load("gdata", "2.x");
function init() {
google.gdata.client.init(handleGDError);
loadDeveloperCalendar();
}
function loadDeveloperCalendar() {
loadCalendarByAddress('fletcheracademycalendar#gmail.com');
}
function padNumber(num) {
if (num <= 9) {
return "0" + num;
}
return num;
}
function loadCalendarByAddress(calendarAddress) {
var calendarUrl = 'https://www.google.com/calendar/feeds/' +
calendarAddress + '/public/full';
loadCalendar(calendarUrl);
}
function loadCalendar(calendarUrl) {
var service = new
google.gdata.calendar.CalendarService('gdata-js-client-samples-simple');
var query = new google.gdata.calendar.CalendarEventQuery(calendarUrl);
query.setOrderBy('starttime');
query.setSortOrder('ascending');
query.setFutureEvents(true);
query.setSingleEvents(true);
query.setMaxResults(5);
service.getEventsFeed(query, listEvents, handleGDError);
}
function handleGDError(e) {
document.getElementById('jsSourceFinal').setAttribute('style', 'display:none');
if (e instanceof Error) {
alert('Error at line ' + e.lineNumber + ' in ' + e.fileName + '\n' + 'Message: ' + e.message);
if (e.cause) {
var status = e.cause.status;
var statusText = e.cause.statusText;
alert('Root cause: HTTP error ' + status + ' with status text of: ' + statusText);
}
} else {
alert(e.toString());
}
}
function listEvents(feedRoot) {
var entries = feedRoot.feed.getEntries();
var eventDiv = document.getElementById('events');
if (eventDiv.childNodes.length > 0) {
eventDiv.removeChild(eventDiv.childNodes[0]);
}
var ul = document.createElement('ul');
//document.getElementById('calendarTitle').innerHTML =
// "Calendar: " + feedRoot.feed.title.$t;
var len = entries.length;
for (var i = 0; i < len; i++) {
var entry = entries[i];
var title = entry.getTitle().getText();
var startDateTime = null;
var startJSDate = null;
var times = entry.getTimes();
if (times.length > 0) {
startDateTime = times[0].getStartTime();
startJSDate = startDateTime.getDate();
}
var entryLinkHref = null;
if (entry.getHtmlLink() != null) {
entryLinkHref = entry.getHtmlLink().getHref();
}
var dateString = (startJSDate.getMonth() + 1) + "/" + startJSDate.getDate();
if (!startDateTime.isDateOnly()) {
dateString += " " + startJSDate.getHours() + ":" +
padNumber(startJSDate.getMinutes());
}
var li = document.createElement('li');
if (entryLinkHref != null) {
entryLink = document.createElement('a');
entryLink.setAttribute('href', entryLinkHref);
entryLink.appendChild(document.createTextNode(title));
li.appendChild(entryLink);
li.appendChild(document.createTextNode(' - ' + dateString));
} else {
li.appendChild(document.createTextNode(title + ' - ' + dateString));
}
ul.appendChild(li);
}
eventDiv.appendChild(ul);
}
google.setOnLoadCallback(init);
</script>
Try this!
Where you have:
var calendarUrl = 'https://www.google.com/calendar/feeds/' + calendarAddress + '/public/full';
you should add something like:
&ctz=Europe/Lisbon
Check here for the correct name of your timezone.