Revision 478

Date:
2015/03/03 11:57:31
Author:
ahitrov
Revision Log:
Control type 'json'
Files:

Legend:

 
Added
 
Removed
 
Modified
  • utf8/core/comps/contenido/components/inputs/json.msn

     
    1 <textarea \
    2 % if ($request->{images_staff_printed}) {
    3 onclick="storeCaret(this)" onkeyup="storeCaret(this)" onselect="storeCaret(this)" \
    4 % }
    5 <% $prop->{readonly} ? 'readonly ' : '' %> name="<% $name %>" id="<% $name %>_textarea" rows="<% $prop->{rows} || 8 %>" cols="<% $prop->{cols} || 8 %>" style="width: 95%;" onkeyup="<% $name %>_changed();"><% $check %></textarea>
    6
    7 <table id="<% $name %>_prev_table" style="width: 95%; display: none;" cellspacing="0" cellpadding="0" border="0">
    8 <tr>
    9 <td width="100%" id="<% $name %>_prev_text" class="bb undo" style="padding: 3px;"></td>
    10 <td style="padding-left: 3px; vertical-align: top;"><a href="#" onclick="return <% $name %>_show();" title="Показать/спрятать прежнее значение"><img src="/contenido/i/modified-19x19.gif" width="19" height="19" class="bb gb"></a></td>
    11 <td style="padding-left: 3px; vertical-align: top;"><a href="#" onclick="return <% $name %>_undo();" title="Отменить изменения"><img src="/contenido/i/undo-19x19.gif" width="19" height="19" class="bb gb"></a></td>
    12 </tr>
    13 </table>
    14 % if ( exists $prop->{rem} && $prop->{rem} ) {
    15 <div style="color:gray; font-size:85%; padding:4px">&raquo; <% $prop->{rem} %></div>
    16 % }
    17 <textarea id="<% $name %>_prev_value" style="display: none;"><% $check %></textarea>
    18
    19 <script type="text/javascript">
    20 var <% $name %>_show_modified = false;
    21 var <% $name %>_show_modified_text = "Прежнее значение не показано. Нажмите кнопку '<b>Показать/спрятать</b>' для просмотра.";
    22
    23 function <% $name %>_changed() {
    24 var t = document.getElementById('<% $name %>_prev_table');
    25 if (document.getElementById('<% $name %>_textarea').value==document.getElementById('<% $name %>_prev_value').value) {
    26 if (t.style.display!='none') {
    27 t.style.display = 'none';
    28 }
    29 return;
    30 }
    31 if (t.style.display=='none') {
    32 document.getElementById('<% $name %>_prev_text').innerHTML = <% $name %>_show_modified_text;
    33 t.style.display = '';
    34 }
    35 }
    36
    37 function <% $name %>_undo() {
    38 document.getElementById('<% $name %>_textarea').value = document.getElementById('<% $name %>_prev_value').value;
    39 <% $name %>_changed();
    40 return false;
    41 }
    42
    43 function <% $name %>_show() {
    44 if (<% $name %>_show_modified) {
    45 document.getElementById('<% $name %>_prev_text').innerHTML = <% $name %>_show_modified_text;
    46 } else {
    47 if (document.all) { // IE
    48 document.getElementById('<% $name %>_prev_text').innerText = document.getElementById('<% $name %>_prev_value').innerText || ' ';
    49 } else {
    50 document.getElementById('<% $name %>_prev_text').innerHTML = document.getElementById('<% $name %>_prev_value').innerHTML || '&nbsp;';
    51 }
    52 }
    53 <% $name %>_show_modified = !<% $name %>_show_modified;
    54 return false;
    55 }
    56 </script>
    57 <%once>
    58
    59 use JSON::XS;
    60
    61 </%once>
    62 <%args>
    63 $name => undef
    64 $check => undef
    65 $prop => {}
    66 $object => undef
    67 </%args>
    68 <%init>
    69
    70 $check = html_escape($check) unless $prop->{no_escape};
    71
    72 if ( ref $check ) {
    73 $check = Encode::encode('utf-8', JSON::XS->new->utf8->encode( $check ));
    74 }
    75
    76 </%init>
  • utf8/core/comps/contenido/components/outputs/json.msn

     
    1 <%once>
    2
    3 use JSON::XS;
    4
    5 </%once>
    6 <%args>
    7
    8 $name => undef
    9 $SETS => undef
    10 $object => undef
    11
    12 </%args>
    13 <%init>
    14
    15 return undef unless ref($SETS);
    16 return undef unless $name;
    17 return undef unless $SETS->{$name};
    18
    19 my ($prop) = grep { $_->{attr} eq $name } $object->structure;
    20 my $class = $object->class;
    21 my $is_extra = grep { ref $_ && $_->{attr} eq $name } $class->extra_properties ? 1 : 0;
    22
    23 my $result;
    24 if ( $is_extra && !$prop->{serialize} ) {
    25 eval { $result = JSON::XS->new->decode( $SETS->{$name} ) };
    26 } else {
    27 $result = $SETS->{$name};
    28 }
    29 warn Dumper $result;
    30 return $result;
    31
    32 </%init>