11/*!
2- evolutility-ui-jquery 1.2.2
3- (c) 2017 Olivier Giulieri
2+ evolutility-ui-jquery 1.2.3
3+ (c) 2019 Olivier Giulieri
44 http://evoluteur.github.io/evolutility-ui-jquery/
55*/
66// default config for Evolutility-UI-jQuery
@@ -13,13 +13,13 @@ Evol.Config = {
1313 localStorage : true ,
1414
1515 // --- using evolutility-server-node
16- //url: 'http://localhost:3000 /api/v1/evolutility /'
16+ //url: 'http://localhost:2000 /api/v1/'
1717
1818} ;
1919;
2020// Evolutility-UI-jQuery Localization Library ENGLISH
2121// https://github.com/evoluteur/evolutility-ui-jquery
22- // (c) 2015 Olivier Giulieri
22+ // (c) 2017 Olivier Giulieri
2323
2424var Evol = Evol || { } ;
2525
@@ -598,7 +598,7 @@ Evol.Format = {
598598 dd = { "error" : "Evol.Format.jsonString" } ;
599599 }
600600 if ( dd === '' ) {
601- return dd ;
601+ return dd ;
602602 } else {
603603 //var txt=JSON.stringify(dd, null, '\t');
604604 var txt = JSON . stringify ( dd , null , 2 ) ;
@@ -788,16 +788,7 @@ Evol.DOM = {
788788 }
789789 } ) ;
790790 return opts ;
791- } /*,
792-
793- toggle: function (items) {
794- var h=['<div class="btn-group" data-toggle="buttons">'];
795- _.each(items, function(item){
796- h.push('<label class="btn btn-info"><input type="radio" name="options" id="',item.id,'">',item.text,'</label>');
797- });
798- h.push('</div>');
799- return h.join('');
800- },*/
791+ }
801792 } ,
802793
803794 toggleCheckbox : function ( $cb , v ) {
@@ -824,13 +815,7 @@ Evol.DOM = {
824815 } ,
825816 buttonsPlusMinus : function ( ) {
826817 return this . buttonsPlus ( ) + this . buttonsMinus ( ) ;
827- } , /*
828- buttonsPrev: function(){
829- return this.buttonsIcon('bPrev', 'chevron-left');
830818 } ,
831- buttonsNext: function(){
832- return this.buttonsIcon('bNext', 'chevron-right');
833- },*/
834819
835820 // --- links ---
836821 link : function ( id , label , url , target ) {
@@ -2018,7 +2003,7 @@ return Backbone.View.extend({
20182003 } ;
20192004 h += '<li data-id="prev"' +
20202005 ( ( pId === 1 ) ?' class="disabled"' :'' ) +
2021- '><a href="javascript:void(0)">« ;</a></li>' ;
2006+ '><a href="javascript:void(0)">< ;</a></li>' ;
20222007 bPage ( 1 ) ;
20232008 if ( pId > 4 && nbPages > 6 ) {
20242009 if ( pId === 5 ) {
@@ -2038,7 +2023,7 @@ return Backbone.View.extend({
20382023 }
20392024 h += '<li data-id="next"' +
20402025 ( ( nbPages > pId ) ? '' : ' class="disabled"' ) +
2041- '><a href="javascript:void(0)">» ;</a></li>' ;
2026+ '><a href="javascript:void(0)">> ;</a></li>' ;
20422027 }
20432028 return h ;
20442029 } ,
@@ -4423,6 +4408,125 @@ Evol.ViewOne.Edit = Evol.View_One.extend({
44234408 *
44244409 *************************************************************************** */
44254410
4411+ Evol . ViewOne . JSON = Evol . View_One . extend ( {
4412+
4413+ events : {
4414+ 'click > .evol-buttons > button' : 'click_button' ,
4415+ 'click .evol-title-toggle' : 'click_toggle' ,
4416+ } ,
4417+
4418+ viewName : 'json' ,
4419+ icon : 'barcode' , // glyphicon-barcode
4420+
4421+ render : function ( ) {
4422+ var dom = Evol . DOM ;
4423+ if ( this . model ) {
4424+ var h = [ ] ,
4425+ jsonStr = JSON . stringify ( this . model , null , 2 ) ;
4426+
4427+ h . push ( dom . panelBegin ( {
4428+ id : 'p-json' ,
4429+ label :Evol . Format . capitalize ( this . uiModel . name ) ,
4430+ label2 : 'JSON'
4431+ } , this . style + ' evo-p-json' , true ) +
4432+ '<fieldset>' +
4433+ dom . label ( 'uimjson' , 'JSON' ) +
4434+ dom . input . textMJSON ( 'uimjson' , jsonStr , 16 ) +
4435+ '</fieldset>' +
4436+ dom . panelEnd ( ) ) ;
4437+
4438+ h . push ( syntaxHighlight ( jsonStr ) ) ;
4439+
4440+ this . _renderButtons ( h , 'json' ) ;
4441+ this . $el . html ( h . join ( '' ) ) ;
4442+ } else {
4443+ this . $el . html ( dom . HTMLMsg ( Evol . i18n . nodata , '' , 'info' ) ) ;
4444+ }
4445+ this . setData ( this . model ) ;
4446+ //this.custOn=false;
4447+ return this ;
4448+ } ,
4449+
4450+ validate : function ( ) {
4451+ var isValid = true ,
4452+ data = this . getData ( ) ,
4453+ $fp = this . _getDOMField ( ) . parent ( ) ;
4454+
4455+ //this.clearMessages();
4456+ isValid = ! Evol . DOM . addRemClass ( $fp , data === null , 'has-error' ) ;
4457+ this . $el . trigger ( 'action' , 'validate' , { valid :isValid } ) ;
4458+ return isValid ?[ ] :[ Evol . i18n . validation . invalid ] ;
4459+ } ,
4460+
4461+ getData : function ( ) {
4462+ var jsonStr = this . _getDOMField ( ) . val ( ) ,
4463+ obj ;
4464+
4465+ if ( jsonStr === '' ) {
4466+ return jsonStr ;
4467+ }
4468+ try {
4469+ obj = $ . parseJSON ( jsonStr ) ;
4470+ } catch ( err ) {
4471+ obj = null ;
4472+ }
4473+ return obj ;
4474+ } ,
4475+
4476+ setData : function ( m ) {
4477+ this . clearError ( ) . _getDOMField ( ) . val ( JSON . stringify ( m . toJSON ( ) , null , 2 ) ) ;
4478+ return this . setTitle ( ) ;
4479+ } ,
4480+
4481+ clear : function ( ) {
4482+ this . _getDOMField ( ) . val ( '' ) ;
4483+ return this ;
4484+ } ,
4485+
4486+ clearError : function ( ) {
4487+ this . _getDOMField ( ) . parent ( ) . removeClass ( 'has-error' ) ;
4488+ return this ;
4489+ } ,
4490+
4491+ _getDOMField : function ( ) {
4492+ return this . $ ( 'textarea' ) ;
4493+ }
4494+
4495+ } ) ;
4496+
4497+ function syntaxHighlight ( json ) {
4498+ if ( typeof json != 'string' ) {
4499+ json = JSON . stringify ( json , undefined , 2 ) ;
4500+ }
4501+ json = json . replace ( / & / g, '&' ) . replace ( / < / g, '<' ) . replace ( / > / g, '>' ) ;
4502+ return json . replace ( / ( " ( \\ u [ a - z A - Z 0 - 9 ] { 4 } | \\ [ ^ u ] | [ ^ \\ " ] ) * " ( \s * : ) ? | \b ( t r u e | f a l s e | n u l l ) \b | - ? \d + (?: \. \d * ) ? (?: [ e E ] [ + \- ] ? \d + ) ? ) / g, function ( match ) {
4503+ var cls = 'number' ;
4504+ if ( / ^ " / . test ( match ) ) {
4505+ if ( / : $ / . test ( match ) ) {
4506+ cls = 'key' ;
4507+ } else {
4508+ cls = 'string' ;
4509+ }
4510+ } else if ( / t r u e | f a l s e / . test ( match ) ) {
4511+ cls = 'boolean' ;
4512+ } else if ( / n u l l / . test ( match ) ) {
4513+ cls = 'null' ;
4514+ }
4515+ return '<span class="' + cls + '">' + match + '</span>' ;
4516+ } ) ;
4517+ }
4518+ ;
4519+ /*! ***************************************************************************
4520+ *
4521+ * evolutility-ui-jquery :: one-json.js
4522+ *
4523+ * View "one json" to edit one backbone model in JSON.
4524+ *
4525+ * https://github.com/evoluteur/evolutility-ui-jquery
4526+ * (c) 2017 Olivier Giulieri
4527+ *
4528+ *************************************************************************** */
4529+
44264530Evol . ViewOne . JSON = Evol . View_One . extend ( {
44274531
44284532 events : {
@@ -5692,6 +5796,12 @@ return Backbone.View.extend({
56925796 case fts . datetime :
56935797 fv . value = formattedDate ( vval ) ;
56945798 break ;
5799+ case fts . int :
5800+ fv . value = vval && typeof ( vval ) === 'string' ?parseInt ( vval ) :null ;
5801+ break ;
5802+ case fts . dec :
5803+ fv . value = vval && typeof ( vval ) === 'string' ?parseFloat ( vval ) :null ;
5804+ break ;
56955805 default :
56965806 fv . value = vval ;
56975807 }
@@ -6221,13 +6331,14 @@ return Backbone.View.extend({
62216331 var h ,
62226332 isReadOnly = this . readonly !== false ,
62236333 that = this ,
6334+ itemName = this . uiModel . name || 'item' ,
62246335 domm = dom . menu ,
62256336 tb = this . buttons ,
62266337 menuDivider = '<li class="divider" data-cardi="x"></li>' ,
62276338 menuDividerH = '<li class="divider-h"></li>' ;
62286339
62296340 function menuItem ( m , noLabel ) {
6230- return domm . hItem ( m . id , noLabel ?'' :m . label , m . icon , m . n ) ;
6341+ return domm . hItem ( m . id , noLabel ?'' :( ( m . label == 'New' ? 'New ' + itemName : m . label ) ) , m . icon , m . n ) ;
62316342 }
62326343 function menuItems ( ms , noLabel ) {
62336344 return _ . map ( ms , function ( m ) {
@@ -6403,8 +6514,7 @@ return Backbone.View.extend({
64036514 collection : this . collection ,
64046515 style : this . style ,
64056516 titleSelector : this . titleSelector ,
6406- router : this . router //,
6407- //iconsPath: this.iconsPath || ''
6517+ router : this . router
64086518 } ;
64096519 vw = new ViewClass ( config ) . render ( ) ;
64106520 break ;
0 commit comments