@@ -572,6 +572,23 @@ Evol.i18n = {
572572
573573 LOCALE :'EN' , // ENGLISH
574574
575+ getLabel : function ( label , string1 , string2 ) {
576+ var l ;
577+ if ( label . indexOf ( '.' ) > - 1 ) {
578+ var ns = label . split ( '.' ) ;
579+ l = this [ ns [ 0 ] ] [ ns [ 1 ] ] ;
580+ } else {
581+ l = label ;
582+ }
583+ if ( string1 ) {
584+ l = l . replace ( '{0}' , string1 ) ;
585+ if ( string2 ) {
586+ l = l . replace ( '{1}' , string2 ) ;
587+ }
588+ }
589+ return l ;
590+ } ,
591+
575592 // --- toolbar ---
576593 View :'View' ,
577594 Edit :'Edit' ,
@@ -621,6 +638,11 @@ Evol.i18n = {
621638 //regex:'"{0}" must match the regular expression pattern for "{1}".'
622639 } ,
623640
641+ // --- charts ---
642+ charts :{
643+ aByB :'{0} by {1}' ,
644+ aB :'{0}: {1}'
645+ } ,
624646
625647 // --- export ---
626648 export :{
@@ -937,7 +959,6 @@ Evol.ViewMany = Backbone.View.extend({
937959 case 0 :
938960 want = ! fv ;
939961 break ;
940-
941962 }
942963 }
943964 return want ;
@@ -1128,7 +1149,6 @@ Evol.ViewMany = Backbone.View.extend({
11281149 var $e = $ ( evt . currentTarget ) ,
11291150 id = $e . data ( 'id' ) ,
11301151 eType = $e . data ( 'type' ) ;
1131-
11321152 Evol . Dico . showDesigner ( id , eType , $e ) ;
11331153 this . $el . trigger ( eType + '.customize' , { id : id , type :eType } ) ;
11341154 }
@@ -1287,13 +1307,13 @@ Evol.ViewMany.Charts = Evol.ViewMany.extend({
12871307 }
12881308 var entityName = EvoUI . capFirstLetter ( uiModel . entities ) ;
12891309 if ( f . type == fTypes . lov ) {
1290- h . push ( EvoUI . Charts . Pie ( entityName + ' by ' + f . label , data , labels , style ) ) ;
1310+ h . push ( EvoUI . Charts . Pie ( Evol . i18n . getLabel ( 'charts.aByB' , entityName , f . label ) , data , labels , style ) ) ;
12911311 } else {
1292- h . push ( EvoUI . Charts . Bars ( entityName + ': ' + f . label , data , labels , style ) ) ;
1312+ h . push ( EvoUI . Charts . Bars ( Evol . i18n . getLabel ( 'charts.aB' , entityName , f . label ) , data , labels , style ) ) ;
12931313 }
12941314 } ) ;
12951315 } else {
1296- h . push ( EvoUI . HTMLMsg ( Evol . i18n . nochart , Evol . i18n . badchart ) ) ;
1316+ h . push ( EvoUI . HTMLMsg ( Evol . i18n . nochart , Evol . i18n . nochart ) ) ;
12971317 }
12981318 h . push ( EvoUI . html . clearer ) ;
12991319 }
@@ -1593,6 +1613,11 @@ Evol.ViewOne = Backbone.View.extend({
15931613 switch ( f . type ) {
15941614 case Evol . Dico . fieldTypes . bool :
15951615 return $f . prop ( 'checked' ) ;
1616+ case Evol . Dico . fieldTypes . integer :
1617+ return parseInt ( $f . val ( ) , 10 ) ;
1618+ case Evol . Dico . fieldTypes . decimal :
1619+ case Evol . Dico . fieldTypes . money :
1620+ return parseFloat ( $f . val ( ) ) ;
15961621 default :
15971622 return $f . val ( ) ;
15981623 }
@@ -1895,12 +1920,6 @@ Evol.ViewOne = Backbone.View.extend({
18951920 h . push ( '</label></div>' ) ;
18961921 } ,
18971922
1898- // prepare to enter a new record
1899- newItem : function ( ) {
1900- return this . clear ( )
1901- . _updateTitle ( Evol . i18n . NewItem . replace ( '{0}' , this . options . uiModel . entity ) . replace ( '{1}' , this . getSummary ( ) ) ) ;
1902- } ,
1903-
19041923 _updateTitle : function ( title ) {
19051924 if ( this . _uTitle ) {
19061925 var opts = this . options ,
@@ -1941,45 +1960,6 @@ Evol.ViewOne = Backbone.View.extend({
19411960 return this ;
19421961 } ,
19431962
1944- commit : function ( fnSuccess , fnError ) {
1945- var msg = this . validate ( ) ;
1946- if ( msg === '' ) {
1947- var that = this ,
1948- entityName = Evol . UI . capFirstLetter ( this . options . uiModel . entity ) ;
1949- if ( this . options . mode === 'new' ) { // || this._isNew
1950- var collec = ( this . model && this . model . collection ) ?this . model . collection :this . collection ;
1951- if ( collec ) {
1952- collec . create ( this . getData ( ) , {
1953- success : function ( m ) {
1954- fnSuccess ( m ) ;
1955- that . setMessage ( 'Record saved.' , Evol . i18n . status . added . replace ( '{0}' , entityName ) . replace ( '{1}' , that . getSummary ( ) ) , 'success' ) ;
1956- that . $el . trigger ( 'save' , 'add' ) ;
1957- that . _updateTitle ( ) ;
1958- } ,
1959- error : fnError
1960- } ) ;
1961- this . options . mode = 'edit' ;
1962- } else {
1963- alert ( 'Can\'t save record b/c no collection is specified.' ) ; //TODO pretty
1964- }
1965- } else {
1966- this . model . set ( this . getData ( ) ) ;
1967- this . model . save ( '' , '' , {
1968- success : function ( m ) {
1969- fnSuccess ( m ) ;
1970- that . setMessage ( 'Record saved.' , Evol . i18n . status . updated . replace ( '{0}' , entityName ) . replace ( '{1}' , that . getSummary ( ) ) , 'success' ) ;
1971- that . $el . trigger ( 'save' , 'update' ) ;
1972- that . _updateTitle ( ) ;
1973- } ,
1974- error : fnError
1975- } ) ;
1976- }
1977- } else {
1978- this . setMessage ( 'Invalid data.' , msg , 'warning' ) ;
1979- }
1980- return this ;
1981- } ,
1982-
19831963 fieldViewId : function ( fid ) {
19841964 return this . prefix + '-' + fid ;
19851965 } ,
@@ -2047,46 +2027,14 @@ Evol.ViewOne = Backbone.View.extend({
20472027 }
20482028 }*/
20492029
2050- setMessage : function ( title , content , style ) {
2051- var $msg = this . $ ( '[data-id="msg"]' ) ;
2052- if ( $msg . length ) {
2053- $msg . html ( '<strong>' + title + '</strong>' + content ) ;
2054- } else {
2055- this . $el . prepend ( Evol . UI . HTMLMsg ( title , content , style ) ) ;
2056- }
2057- return this ;
2058- } ,
2059-
2060- clearMessage : function ( ) {
2061- var $msg = this . $ ( '[data-id="msg"]' )
2062- . fadeOut ( 300 , function ( ) {
2063- $msg . remove ( ) ;
2064- } ) ;
2065- return this ;
2066- } ,
2067-
20682030 clearMessages : function ( ) {
2069- return this . clearErrors ( ) . clearMessage ( ) ;
2031+ return this . clearErrors ( ) ;
20702032 } ,
20712033
20722034 click_button : function ( evt ) {
2073- var that = this ,
2074- buttonId = $ ( evt . currentTarget ) . data ( 'id' ) ;
2035+ var buttonId = $ ( evt . currentTarget ) . data ( 'id' ) ;
20752036 evt . stopImmediatePropagation ( ) ;
2076- if ( buttonId === 'cancel' ) {
2077-
2078- } else {
2079- this . commit ( function ( m ) {
2080- if ( buttonId === 'save-add' ) {
2081- that . newItem ( ) ;
2082- } else {
2083- that . model = m ;
2084- that . setModel ( m ) ;
2085- }
2086- } , function ( ) {
2087- alert ( 'error' ) ; //TODO make it nice looking
2088- } ) ;
2089- }
2037+ this . $el . trigger ( 'action' , buttonId ) ;
20902038 } ,
20912039
20922040 click_toggle : function ( evt ) {
@@ -2314,13 +2262,14 @@ Evol.ViewOne.Mini = Evol.ViewOne.extend({
23142262
23152263var Evol = Evol || { } ;
23162264
2265+ // toolbar widget which also acts as a controller for all views "one" and "many" as well as actions
23172266Evol . ViewToolbar = Backbone . View . extend ( {
23182267
23192268 events : {
23202269 'click .nav a' : 'click_toolbar' ,
23212270 'list.navigate div' : 'click_navigate' ,
23222271 'click #XP' : 'click_download' ,
2323- 'save > div' : 'saveItem '
2272+ 'action > div' : 'action_view '
23242273 } ,
23252274
23262275 options : {
@@ -2483,7 +2432,7 @@ Evol.ViewToolbar = Backbone.View.extend({
24832432 this . _isNew = true ; // TODO model.isNew
24842433 this . model = new opts . modelClass ( ) ;
24852434 this . model . collection = collec ;
2486- this . curView . newItem ( this . model ) ;
2435+ this . newItem ( ) ;
24872436 this . curView . options . mode = 'new' ;
24882437 } else {
24892438 this . _isNew = false ;
@@ -2668,23 +2617,75 @@ Evol.ViewToolbar = Backbone.View.extend({
26682617 return this ;
26692618 } ,
26702619
2671- saveItem : function ( evt , ui ) {
2672- if ( ui === 'add' ) {
2673- this . _isNew = false ; // TODO not if saveandaddnew
2674- this . setButtons ( 'edit' ) ;
2620+ saveItem : function ( saveAndAdd ) {
2621+ var that = this ,
2622+ vw = this . curView ,
2623+ msg = vw . validate ( ) ;
2624+
2625+ function fnSuccess ( m ) {
2626+ if ( saveAndAdd ) {
2627+ that . newItem ( ) ;
2628+ } else {
2629+ that . model = m ;
2630+ that . _isNew = false ;
2631+ that . setButtons ( 'edit' ) ;
2632+ vw . setModel ( m ) ;
2633+ }
2634+ vw . _updateTitle ( ) ;
2635+ }
2636+
2637+ if ( msg === '' ) {
2638+ var entityName = Evol . UI . capFirstLetter ( this . options . uiModel . entity ) ;
2639+ if ( this . _isNew ) {
2640+ var collec = ( this . model && this . model . collection ) ?this . model . collection :this . collection ;
2641+ if ( collec ) {
2642+ collec . create ( this . getData ( ) , {
2643+ success : function ( m ) {
2644+ fnSuccess ( m ) ;
2645+ that . setMessage ( 'Record saved.' , Evol . i18n . getLabel ( 'status.added' , entityName , vw . getSummary ( ) ) , 'success' ) ;
2646+ } ,
2647+ error :function ( err ) {
2648+ alert ( 'error' ) ;
2649+ }
2650+ } ) ;
2651+ this . options . mode = 'edit' ;
2652+ } else {
2653+ alert ( 'Can\'t save record b/c no collection is specified.' ) ; //TODO pretty
2654+ }
2655+ } else {
2656+ this . model . set ( this . getData ( ) ) ;
2657+ this . model . save ( '' , '' , {
2658+ success : function ( m ) {
2659+ fnSuccess ( m ) ;
2660+ that . setMessage ( 'Record saved.' , Evol . i18n . getLabel ( 'status.updated' , entityName , vw . getSummary ( ) ) , 'success' ) ;
2661+ } ,
2662+ error :function ( err ) {
2663+ alert ( 'error' ) ;
2664+ }
2665+ } ) ;
2666+ }
2667+ } else {
2668+ this . setMessage ( 'Invalid data.' , msg , 'warning' ) ;
26752669 }
2670+ return this ;
26762671 } ,
26772672
2678- newItem : function ( ) {
2673+ cancelItem : function ( ) {
2674+
2675+ } ,
26792676
2677+ newItem : function ( ) {
2678+ var vw = this . curView ;
2679+ return vw . clear ( )
2680+ . _updateTitle ( Evol . i18n . getLabel ( 'NewItem' , this . options . uiModel . entity , vw . getSummary ( ) ) ) ;
26802681 } ,
26812682
26822683 deleteItem : function ( ) {
26832684 var entityName = this . options . uiModel . entity ,
26842685 entityValue = this . curView . getSummary ( ) ,
26852686 delModel = this . curView . model ;
26862687 // TODO good looking msgbox
2687- if ( delModel && confirm ( Evol . i18n . DeleteEntity . replace ( '{0} ', entityName ) . replace ( '{1}' , entityValue ) ) ) {
2688+ if ( delModel && confirm ( Evol . i18n . getLabel ( 'DeleteEntity ', entityName , entityValue ) ) ) {
26882689 var that = this ,
26892690 collec = this . collection ,
26902691 delIdx = _ . indexOf ( collec . models , delModel ) ,
@@ -2712,7 +2713,7 @@ Evol.ViewToolbar = Backbone.View.extend({
27122713 this . model = newModel ;
27132714 that . curView . setModel ( newModel ) ;
27142715 }
2715- that . curView . setMessage ( 'Record Deleted.' , Evol . i18n . status . deleted . replace ( '{0}' , Evol . UI . capFirstLetter ( entityName ) ) . replace ( '{1}' , entityValue ) , 'success' ) ;
2716+ that . setMessage ( 'Record Deleted.' , Evol . i18n . getLabel ( ' status.deleted' , Evol . UI . capFirstLetter ( entityName ) , entityValue ) , 'success' ) ;
27162717 } ,
27172718 error :function ( err ) {
27182719 alert ( 'error' ) ;
@@ -2721,6 +2722,29 @@ Evol.ViewToolbar = Backbone.View.extend({
27212722 }
27222723 } ,
27232724
2725+ setMessage : function ( title , content , style ) {
2726+ var $msg = this . $ ( '[data-id="msg"]' ) ;
2727+ if ( $msg . length ) {
2728+ $msg . html ( '<strong>' + title + '</strong>' + content ) . show ( ) ;
2729+ } else {
2730+ this . $el . prepend ( Evol . UI . HTMLMsg ( title , ' ' + content , style ) ) ;
2731+ }
2732+ return this ;
2733+ } ,
2734+
2735+ clearMessage : function ( ) {
2736+ this . $ ( '[data-id="msg"]' ) . remove ( ) ;
2737+ return this ;
2738+ } ,
2739+
2740+ action_view : function ( evt , actionId ) {
2741+ if ( actionId === 'cancel' ) {
2742+
2743+ } else {
2744+ this . saveItem ( actionId === 'save-add' ) ;
2745+ }
2746+ } ,
2747+
27242748 click_toolbar : function ( evt ) {
27252749 var $e = $ ( evt . target ) ;
27262750 if ( $e . tagName !== 'A' ) {
@@ -2746,7 +2770,7 @@ Evol.ViewToolbar = Backbone.View.extend({
27462770 case 'next' :
27472771 this . browse ( toolId ) ;
27482772 break ;
2749- case 'new-field' :// ui-dico
2773+ case 'new-field' :
27502774 Evol . Dico . showDesigner ( '' , 'field' , $e ) ;
27512775 break ;
27522776 //case 'new-panel':// ui-dico
@@ -2756,18 +2780,16 @@ Evol.ViewToolbar = Backbone.View.extend({
27562780 }
27572781 break ;
27582782 }
2759- evt . stopImmediatePropagation ( ) ;
27602783 this . $el . trigger ( 'toolbar.' + toolId ) ;
27612784 } ,
27622785
27632786 click_navigate : function ( evt , ui ) {
2764- var m = this . model . collection . get ( ui . id ) ;
2787+ var m = this . collection . get ( ui . id ) ;
2788+ evt . stopImmediatePropagation ( ) ;
27652789 this . model = m ;
27662790 this . setView ( this . _prevOne || 'edit' ) ;
2767- this . curView . model = m ;
2791+ this . curView . setModel ( m ) ;
27682792 // todo: change model for all views / or model event
2769- this . curView . render ( ) ;
2770- evt . stopImmediatePropagation ( ) ;
27712793 } ,
27722794
27732795 click_download : function ( evt ) {
0 commit comments