Commit ee1289b3b6be75403d2b7241337a33b3fe921c27

  • avatar
  • Sergey 'Jin' Bostandzhyan <jin @deve…per.digitalstrom.org>
  • Fri Jun 25 16:46:31 CEST 2010
Replace on/off button with a blink button

Implements #399
dss-setup-interface/dSS/data/DeviceStore.js
(1 / 1)
  
66 var deviceRecord = Ext.data.Record.create([
77 {name:"name"},
88 {name:"dsid", mapping: "id"},
9 {name:"on"},
9 {name:"blink", defaultValue: false},
1010 {name:"modulatorDsid"},
1111 {name:"modulatorName"},
1212 {name:"zoneId"},
dss-setup-interface/dSS/grid/DevicePanel.js
(41 / 44)
  
1212dSS.grid.DevicePanel = Ext.extend(Ext.grid.GridPanel, {
1313 initComponent: function() {
1414
15 var stateRenderer = function(value, metaData, record, rowIndex, colIndex, store) {
15 var blinkRenderer = function(value, metaData, record, rowIndex, colIndex, store) {
1616 if(record.get('isPresent') === false) {
1717 metaData.css = 'isDisabled';
1818 }
1919 else {
20 if(record.get('on')) {
21 metaData.css = 'isOn';
20 if(record.get('blink') === true) {
21 metaData.css = 'blinkActive';
2222 } else {
23 metaData.css = 'isOff';
23 metaData.css = 'blink';
2424 }
2525 }
2626 return String.format('<img class="padding-img" src="{0}"/>',Ext.BLANK_IMAGE_URL);
4242
4343
4444 var deviceCols = [
45 {header: _("on"), width: 30, resizable: false, sortable: true, dataIndex: 'on', renderer: stateRenderer, id: 'on'},
45 {header: _("blink"), width: 25, resizable: false, sortable: false, dataIndex: 'blink', renderer: blinkRenderer, id: 'blink'},
4646 {header: "dsid", width: 150, sortable: true, dataIndex: 'dsid', id: 'dsid'},
4747 {header: _("name"), width: 150, sortable: true, dataIndex: 'name', id: 'name'},
4848 {header: _("meter name"), width: 100, sortable: true, dataIndex: 'modulatorName', id: 'modulatorName' },
234234 return;
235235 }
236236
237 if (dataIndex === 'on') {
238 Ext.Ajax.request({
239 url: record.get('on') ? '/json/device/turnOff' : '/json/device/turnOn',
240 disableCaching: true,
241 method: "GET",
242 params: { dsid: record.get('dsid') },
243 success: function(result, request) {
244 try {
245 var jsonData = Ext.util.JSON.decode(result.responseText);
246 if(jsonData.ok) {
247 record.set('on', record.get('on') ? false : true );
248 record.commit();
249 }
250 } catch(err) {
251 Ext.MessageBox.alert('Error', err);
252 }
253 }
254 });
237 if (dataIndex === 'blink') {
238 this.sendBlinkRequest(record);
255239 } else if (dataIndex === 'locked') {
256240 Ext.Ajax.request({
257241 url: record.get('locked') ? '/json/device/unlock' : '/json/device/lock',
544544 });
545545 },
546546
547 sendBlinkRequest: function(record) {
548 record.set('blink', true);
549 var unblink = function(record) {
550 record.set('blink', false);
551 }
552
553 Ext.Ajax.request({
554 url: '/json/device/blink',
555 disableCaching: true,
556 method: "GET",
557 scope: this,
558 params: { dsid : record.get('dsid') },
559 success: function(result, request) {
560 try {
561 var jsonData = Ext.util.JSON.decode(result.responseText);
562 if (!jsonData.ok) {
563 Ext.MessageBox.alert(_("Could not blink"), jsonData.message);
564 }
565 } catch (err) {
566 Ext.MessageBox.alert(_("Error"),
567 _("Could send blink device command to dSS") + ": " + err);
568 }
569 unblink.defer(2000, this, [ record ]);
570 },
571 failure: function(result, request) {
572 Ext.MessageBox.alert(_("Error"),
573 _("Could send blink device command to dSS"));
574 unblink.defer(2000, this, [ record ]);
575 }
576 });
577 },
578
547579 blinkDevice: function(item, event, rowIndex) {
548580 var records;
549581 var store = this.getStore();
595595 continue;
596596 }
597597
598 Ext.Ajax.request({
599 url: '/json/device/blink',
600 disableCaching: true,
601 method: "GET",
602 scope: this,
603 params: { dsid : records[i].get('dsid') },
604 success: function(result, request) {
605 try {
606 var jsonData = Ext.util.JSON.decode(result.responseText);
607 if(!jsonData.ok) {
608 Ext.MessageBox.alert(_("Could not blink"), jsonData.message);
609 }
610 }
611 catch (err) {
612 Ext.MessageBox.alert(_("Error"), _("Could send blink device command to dSS") + ": " + err);
613 }
614 },
615 failure: function(result, request) {
616 Ext.MessageBox.alert(_("Error"), _("Could send blink device command to dSS"));
617 }
618 });
598 this.sendBlinkRequest(records[i]);
599
619600 }
620601 },
621602