@@ -18,7 +18,7 @@ var filterOps = {
1818 }
1919}
2020
21- module . exports = function DeviceColumnService ( $filter , gettext ) {
21+ module . exports = function DeviceColumnService ( $filter , $compile , gettext ) {
2222 // Definitions for all possible values.
2323 return {
2424 state : DeviceStatusCell ( {
@@ -252,8 +252,14 @@ module.exports = function DeviceColumnService($filter, gettext) {
252252 return device . provider ? device . provider . name : ''
253253 }
254254 } )
255- , notes : TextCell ( {
255+ , notes : XEditableCell ( {
256256 title : gettext ( 'Notes' )
257+ , compile : $compile
258+ , scopeRequired : true
259+ , attrs : {
260+ model : 'device.notes'
261+ , onbeforesave : 'updateNote(device.serial, $data)'
262+ }
257263 , value : function ( device ) {
258264 return device . notes || ''
259265 }
@@ -613,3 +619,38 @@ function DeviceStatusCell(options) {
613619 }
614620 } )
615621}
622+
623+ function XEditableCell ( options ) {
624+ return _ . defaults ( options , {
625+ title : options . title
626+ , defaultOrder : 'asc'
627+ , build : function ( scope ) {
628+ var td = document . createElement ( 'td' )
629+ , a = document . createElement ( 'a' )
630+
631+ // Ref: http://vitalets.github.io/angular-xeditable/#text-simple
632+ a . setAttribute ( 'href' , '#' )
633+ a . setAttribute ( 'editable-text' , options . attrs . model )
634+ a . setAttribute ( 'onbeforesave' , options . attrs . onbeforesave )
635+
636+ a . appendChild ( document . createTextNode ( options . attrs . model ) )
637+ td . appendChild ( a )
638+
639+ // compile with new scope
640+ options . compile ( td ) ( scope )
641+ return td
642+ }
643+ , update : function ( td , item ) {
644+ var a = td . firstChild
645+ , t = a . firstChild
646+ t . nodeValue = options . value ( item ) || 'click to add'
647+ return td
648+ }
649+ , compare : function ( a , b ) {
650+ return compareIgnoreCase ( options . value ( a ) , options . value ( b ) )
651+ }
652+ , filter : function ( item , filter ) {
653+ return filterIgnoreCase ( options . value ( item ) , filter . query )
654+ }
655+ } )
656+ }
0 commit comments