commit 89316973ea988e7d41a2bfee256e56dfc0baa524
parent 4fd7bdfee4723b3b346361f243a3be2e348b87d1
Author: Timo A. Hummel <timo@netraver.de>
Date: Sat, 4 Jun 2011 10:27:10 +0200
Escape html entities when displaying the part, added a bit documentation
Diffstat:
1 file changed, 62 insertions(+), 1 deletion(-)
diff --git a/frontend/js/Components/Part/PartDisplay.js b/frontend/js/Components/Part/PartDisplay.js
@@ -1,7 +1,18 @@
+/**
+ * @class PartDB2.PartDisplay
+ * <p>This component displays information about a specific part.</p>
+ */
Ext.define('PartDB2.PartDisplay', {
extend: 'Ext.panel.Panel',
bodyCls: 'partdisplay',
+
+ /**
+ * Initializes the component and adds a template as well as the add/remove stock and edit part buttons.
+ */
initComponent: function () {
+ /**
+ * Create the template
+ */
this.tpl = new Ext.XTemplate(
'<h1>{name}</h1>',
'<table>',
@@ -31,6 +42,9 @@ Ext.define('PartDB2.PartDisplay', {
'</tr>',
'</table>');
+ /**
+ * Create the "add stock" button
+ */
this.addButton = new Ext.Button({
text: i18n("Add Stock"),
cls:'x-btn-text-icon',
@@ -38,6 +52,9 @@ Ext.define('PartDB2.PartDisplay', {
handler: Ext.bind(this.addPartPrompt, this)
});
+ /**
+ * Create the "remove stock" button
+ */
this.deleteButton = new Ext.Button({
text: i18n("Remove Stock"),
cls:'x-btn-text-icon',
@@ -45,12 +62,18 @@ Ext.define('PartDB2.PartDisplay', {
handler: Ext.bind(this.deletePartPrompt, this)
});
+ /**
+ * Create the "edit part" button
+ */
this.editButton = new Ext.Button({
text: i18n("Edit Part"),
icon: 'resources/silkicons/brick_edit.png',
handler: Ext.bind(function () { this.fireEvent("editPart", this.record.get("id"));}, this)
});
+ /**
+ * Create the toolbar which holds our buttons
+ */
this.tbar = Ext.create("Ext.toolbar.Toolbar", {
enableOverflow: true,
items: [
@@ -60,17 +83,40 @@ Ext.define('PartDB2.PartDisplay', {
]
});
+ /**
+ * Add the event "editPart". This event is fired as soon as the "edit" button is clicked.
+ *
+ * @todo Add the events "addStock" and "removeStock" and manage these events from the PartManager.
+ */
this.addEvents("editPart");
this.callParent();
},
+ /**
+ * Sets the values for the template.
+ *
+ * Note that the data of the record is applied with htmlentities(), i.e. <b>Test</b> will be
+ * displayed as such and not in bold.
+ */
setValues: function (r) {
this.record = r;
- this.tpl.overwrite(this.getTargetEl(), r.data);
+
+ var values = {};
+ for (var i in r.data) {
+ values[i] = htmlentities(r.data[i]);
+ }
+
+ this.tpl.overwrite(this.getTargetEl(), values);
},
+ /**
+ * Prompt the user for the stock level he wishes to add.
+ */
addPartPrompt: function () {
Ext.Msg.prompt(i18n("Add stock"), i18n("Amount"), this.addPartHandler, this);
},
+ /**
+ * Callback after the "add stock" dialog is complete.
+ */
addPartHandler: function (btn,a,c) {
if (btn == "ok") {
var call = new PartDB2.ServiceCall(
@@ -83,9 +129,15 @@ Ext.define('PartDB2.PartDisplay', {
call.doCall();
}
},
+ /**
+ * Prompts the user for the stock level to decrease for the item.
+ */
deletePartPrompt: function () {
Ext.Msg.prompt(i18n("Remove Stock"), i18n("Amount"), this.deletePartHandler, this);
},
+ /**
+ * Callback after the "delete stock" dialog is complete.
+ */
deletePartHandler: function (btn,a,c) {
if (btn == "ok") {
var call = new PartDB2.ServiceCall(
@@ -98,9 +150,15 @@ Ext.define('PartDB2.PartDisplay', {
call.doCall();
}
},
+ /**
+ * Reloads the current part
+ */
reloadPart: function () {
this.loadPart(this.record.get("id"));
},
+ /**
+ * Load the part from the database.
+ */
loadPart: function (id) {
var call = new PartDB2.ServiceCall(
"Part",
@@ -110,6 +168,9 @@ Ext.define('PartDB2.PartDisplay', {
call.setHandler(Ext.bind(this.onPartLoaded, this));
call.doCall();
},
+ /**
+ * Callback after the part is loaded
+ */
onPartLoaded: function (response) {
this.record.set(response);
this.setValues(this.record);