RateAndComment.js
define("widgets/RateAndComment", [ "dojo", "dijit", "dijit/_Widget",
"dijit/_TemplatedMixin", "dijit/_WidgetsInTemplateMixin",
"dojo/text!widgets/templates/RateAndComment.html", "dojox/form/Rating",
"dojo/data/ItemFileWriteStore", "dijit/form/Textarea", "dijit/Dialog",
"dijit/form/Button", "dijit/TitlePane"
], function(dojo, dijit, _Widget, _TemplatedMixin, _WidgetsInTemplateMixin) {
dojo.declare("widgets.RateAndComment", [ dijit._Widget,
dijit._TemplatedMixin, dijit._WidgetsInTemplateMixin ],
{
// Pfad zur Schablone
templateString : dojo.cache("widgets", "templates/RateAndComment.html"),
movieTitle : "",
rcStore : new dojo.data.ItemFileWriteStore({
data : {
items : []
}
}),
// Diese Methode überschreiben, um angepasstes Verhalten während dijit-Erstellung
// zu erhalten.
// Allgemeine Operationen für Konstruktor:
// 1) Nicht primitive Typen initialisieren (d. h. Objekte und Arrays)
// 2) Zusätzliche Eigenschaften hinzufügen, die von aufeinanderfolgenden
// Lebenszyklusmethoden benötigt werden
constructor : function() {
},
getComment : function(){
return this.comments.get('value');
},
getRating : function(){
return this.rating.get('value');
},
setComment : function(value){
this.comments.set("value", value);
},
setRating : function(value){
this.rating.set("value", value);
},
showFeedbackTools : function(movieTitle){
this.movieTitle = movieTitle;
this.dialogbox.show();
},
saveFeedback : function(){
var userRating = this.getRating();
var userComment = this.getComment();
this.rcStore.newItem({
title : this.movieTitle,
comment : userComment,
rating : userRating
});
dojo.create("li", {
innerHTML : "<b>Title:</b> " + this.movieTitle + " <b>Rating:</b>"
+ userRating + "<br> <b>Comments:</b> " + userComment
}, this.feedbacklist);
this.dialogbox.hide();
this.setComment("");
this.setRating(0);
},
getCommentsByMovieTitle : function(movieTitle){
var comments = [];
var store = this.rcStore;
this.rcStore.fetch({
query : {
title : movieTitle
},
onComplete : function(items, request){
dojo.forEach(items, function(item){
comments.push(store.getValue(item, "comment"));
});
}
});
return comments;
},
// Wenn diese Methode aufgerufen wird, werden alle Variablen
// "untergemischt".
// Allgemeine Operationen für postMixInProperties
// 1) Werte für in der HTML-Dateischablone definierte Widget-Eigenschaftsvariablen
// bearbeiten und zuordnen
postMixInProperties : function() {
},
// postCreate() wird nach buildRendering() aufgerufen. Dies dient zur
// Überschreibung, wenn
// Sie DOM-Knoten aufrufen und/oder bearbeiten müssen, die in Ihrem
// Widget enthalten sind.
// Auf DOM-Knoten und -Widgets, bei denen das Attribut dojoAttachPoint
// angegeben ist, ist jetzt
// ein direkter Zugriff als Felder auf "this" möglich.
// Allgemeine Operationen für postCreate
// 1) In buildRendering() erstellten DOM-Knoten aufrufen und
// bearbeiten
// 2) Neue DOM-Knoten oder Widgets hinzufügen
postCreate : function() {
}
});
});
RateAndComment.html
<div class="RateAndComment">
<div data-dojo-type="dijit.Dialog" data-dojo-attach-point="dialogbox"
data-dojo-props="title: 'Bewerten und Kommentieren!'">
Rate: <div data-dojo-type="dojox.form.Rating" data-dojo-attach-point = "rating" data-dojo-props = "numStars: '5'"></div>
<br>
<br>
Comments: <div data-dojo-type="dijit.form.Textarea" data-dojo-attach-point = "comments" style="width: 60%;"></div>
<br>
<button data-dojo-type="dijit.form.Button" data-dojo-attach-event="onClick: saveFeedback">Submit</button>
</div>
<div data-dojo-type="dijit.TitlePane" data-dojo-props="title: 'Protokoll der Bewertungen und Kommentare'">
<ol data-dojo-attach-point="feedbacklist"></ol>
</div>
</div>
