Revision 618

Date:
2016/11/09 15:02:51
Author:
ahitrov
Revision Log:
AJAX status change bug fix.

Files:

Legend:

 
Added
 
Removed
 
Modified
  • utf8/core/comps/contenido/ajax/document_status.html

     
    10 10 $id => undef
    11 11 $class => undef
    12 12 $status => undef
    13 $toggle => undef
    13 14 $params => undef
    14 15
    15 16 </%args>
     
    17 18
    18 19 my %result;
    19 20
    20 if ( $id && $id =~ /^\d+$/ && $class && $class =~ /::/ && defined $status ) {
    21 if ( $id && $id =~ /^\d+$/ && $class && $class =~ /--/ && ($toggle || defined $status) ) {
    22 $class =~ s/-/:/g;
    21 23 my $section = $keeper->get_section_by_id( $s ) if $s;
    22 24 my $document = $keeper->get_document_by_id( $id, class => $class );
    23 25 my %filter;
     
    35 37
    36 38 # стандартная жопка таблицы...
    37 39 push @columns, {attr => '_act_', rusname => 'Действия'};
    38
    39 $document->status( $status );
    40 $document->store;
    41 40
    41 if ( defined $status ) {
    42 $document->status( $status );
    43 $document->store;
    44 } else {
    45 my ($prop) = grep { $_->{attr} eq 'status' } $document->structure;
    46 if ( ref $prop && exists $prop->{cases} && ref $prop->{cases} eq 'ARRAY' && scalar @{$prop->{cases}} == 2 ) {
    47 $document->status( $prop->{cases}[0][0] == $document->status ? $prop->{cases}[1][0] : $prop->{cases}[0][0] );
    48 $document->store;
    49 }
    50 }
    51
    42 52 my $html = $m->scomp('/contenido/components/section_browse_row.msn', no_tr => 1,
    43 53 document => $document, columns => \@columns, section => $section,
    44 54 lookup_elemets => {}, filter => \%filter, params_unsection => $params_unsection, params_unclassed => $params_unclassed
  • utf8/core/comps/contenido/components/section_browse.msn

     
    63 63 return dumped_text;
    64 64 }
    65 65
    66 $(document).ready(function(){
    67 $('.move-up').on('click', function( ev ){
    68 ev.preventDefault();
    69 var $nID = $(this).data('id');
    70 $.ajax({
    71 'url' : '/contenido/ajax/document_move.html',
    72 'data' : { 's' : <% ref $section ? $section->id : 0 %>, 'id' : $nID, 'move' : 'up' },
    73 'dataType' : 'json',
    74 'success' : function( data ){
    75 if ( data.error ) {
    76 alert( data.error );
    77 } else if ( data.before ) {
    78 var $nBefore = data.before;
    79 $('#row-' + $nID).insertBefore('#row-' + $nBefore);
    80 }
    81 }
    82 });
    83 });
    84 $('.move-down').on('click', function( ev ){
    85 ev.preventDefault();
    86 var $nID = $(this).data('id');
    87 $.ajax({
    88 'url' : '/contenido/ajax/document_move.html',
    89 'data' : { 's' : <% ref $section ? $section->id : 0 %>, 'id' : $nID, 'move' : 'down' },
    90 'dataType' : 'json',
    91 'success' : function( data ){
    92 if ( data.error ) {
    93 alert( data.error );
    94 } else if ( data.after ) {
    95 var $nAfter = data.after;
    96 $('#row-' + $nID).insertAfter('#row-' + $nAfter);
    97 }
    98 }
    99 });
    100 });
    66 var oMenus = {
    67 % my $cls_count = scalar keys %document_classes;
    101 68 % foreach my $class ( keys %document_classes ) {
    69 % $cls_count--;
    102 70 % my $class_name = $class;
    103 71 % $class_name =~ s/:/-/g;
    104 72 % my ($prop) = grep { $_->{attr} eq 'status' } $class->new( $keeper )->structure;
     
    114 82 % push @menu, "'$key' : { 'name' : '$name' }";
    115 83 % }
    116 84 % }
    117 $.contextMenu({
    118 selector: '.context-menu-<% $class_name %>',
    119 trigger: 'left',
    120 callback: function(key, options) {
    121 var nID = parseInt($(this).data('id'));
    122 if ( nID != key ) {
    123 $.ajax({
    124 'url' : '/contenido/ajax/document_status.html',
    125 'data' : { 'class' : '<% $class %>', 'id' : nID, 'status' : key, 's' : <% ref $section ? $section->id : 0 %>, 'params' : '<% $params %>' },
    126 'dataType' : 'json',
    127 'success' : function( data ) {
    128 if ( data.error ) {
    129 alert( data.error );
    85 '<% $class_name %>' : { <% join(", ", @menu) %> }<% $cls_count ? ',' : '' %>
    86 % }
    87 % }
    88
    89 }
    90
    91 function set_status_toggle( ev, nID, $class_name ) {
    92 ev.preventDefault();
    93 $.ajax({
    94 'url' : '/contenido/ajax/document_status.html',
    95 'data' : { 'class' : $class_name, 'id' : nID, 'toggle' : 1, 's' : <% ref $section ? $section->id : 0 %>, 'params' : '<% $params %>' },
    96 'dataType' : 'json',
    97 'success' : function( data ) {
    98 if ( data.error ) {
    99 alert( data.error );
    100 }
    101 if ( data.success ) {
    102 $('#row-' + nID).html(data.html);
    103 $('#status-set-'+ nID).on('click', function( ev ) {
    104 set_status_toggle(ev, nID, $class_name)
    105 });
    106 }
    107 }
    108 });
    109 }
    110
    111 function set_status( $selector, $class_name ) {
    112 var oMenu = oMenus[$class_name];
    113 $.contextMenu({
    114 selector: $selector,
    115 trigger: 'left',
    116 callback: function(key, options) {
    117 var nID = parseInt($(this).data('id'));
    118 if ( nID != key ) {
    119 $.ajax({
    120 'url' : '/contenido/ajax/document_status.html',
    121 'data' : { 'class' : $class_name, 'id' : nID, 'status' : key, 's' : <% ref $section ? $section->id : 0 %>, 'params' : '<% $params %>' },
    122 'dataType' : 'json',
    123 'success' : function( data ) {
    124 if ( data.error ) {
    125 alert( data.error );
    126 }
    127 if ( data.success ) {
    128 $('#row-' + nID).html(data.html);
    129 set_status( '#status-set-'+ nID, $class_name);
    130 }
    130 131 }
    131 if ( data.success ) {
    132 $('#row-' + nID).html(data.html);
    133 }
    132 });
    133 }
    134 },
    135 items: oMenu
    136 });
    137 }
    138
    139 $(document).ready(function(){
    140 $('.move-up').on('click', function( ev ){
    141 ev.preventDefault();
    142 var $nID = $(this).data('id');
    143 $.ajax({
    144 'url' : '/contenido/ajax/document_move.html',
    145 'data' : { 's' : <% ref $section ? $section->id : 0 %>, 'id' : $nID, 'move' : 'up' },
    146 'dataType' : 'json',
    147 'success' : function( data ){
    148 if ( data.error ) {
    149 alert( data.error );
    150 } else if ( data.before ) {
    151 var $nBefore = data.before;
    152 $('#row-' + $nID).insertBefore('#row-' + $nBefore);
    134 153 }
    135 });
    136 }
    137 // var m = "clicked: " + key;
    138 // window.console && console.log(m) || alert(m);
    139 },
    140 items: {
    141 <% join(",\n", @menu) %>
    142 }
    143 });
    154 }
    155 });
    156 });
    157
    158 $('.move-down').on('click', function( ev ){
    159 ev.preventDefault();
    160 var $nID = $(this).data('id');
    161 $.ajax({
    162 'url' : '/contenido/ajax/document_move.html',
    163 'data' : { 's' : <% ref $section ? $section->id : 0 %>, 'id' : $nID, 'move' : 'down' },
    164 'dataType' : 'json',
    165 'success' : function( data ){
    166 if ( data.error ) {
    167 alert( data.error );
    168 } else if ( data.after ) {
    169 var $nAfter = data.after;
    170 $('#row-' + $nID).insertAfter('#row-' + $nAfter);
    171 }
    172 }
    173 });
    174 });
    175
    176 % foreach my $class ( keys %document_classes ) {
    177 % my $class_name = $class;
    178 % $class_name =~ s/:/-/g;
    179 % my ($prop) = grep { $_->{attr} eq 'status' } $class->new( $keeper )->structure;
    180 % if ( ref $prop && exists $prop->{cases} && ref $prop->{cases} eq 'ARRAY' ) {
    181 % if ( scalar @{$prop->{cases}} > 2 ) {
    182 set_status( '.context-menu-<% $class_name %>', '<% $class_name %>' );
    183 % } else {
    184 $('.context-menu-<% $class_name %>').on('click', function( ev ) {
    185 var nID = parseInt($(this).data('id'));
    186 set_status_toggle(ev, nID, '<% $class_name %>')
    187 });
    188 % }
    144 189 % }
    145 190 % }
    146 191 });
  • utf8/core/comps/contenido/components/section_browse_row.msn

     
    161 161 src="/contenido/i/actions/delete.gif" width="14" height="17" alt="Удалить документ" align="absmiddle" border="0" hspace="1"></a>\
    162 162 % if ( $document->status != 0 ) {
    163 163 <a href="document.html?deactivate=1&id=<% $document->id %>&class=<% $document->class %><% $params_unclassed ? '&'.$params_unclassed : '' %>"
    164 class="context-menu-<% $class_name %>" title="Статус документа" data-id="<% $document->id %>"><img
    164 class="context-menu-<% $class_name %>" id="status-set-<% $document->id %>" title="Статус документа" data-id="<% $document->id %>"><img
    165 165 src="/contenido/i/actions/activate.gif" width="14" height="17" alt="Документ активен" align="absmiddle" border="0" hspace="1"></a>\
    166 166 % } else {
    167 167 <a href="document.html?activate=1&id=<% $document->id %>&class=<% $document->class %><% $params_unclassed ? '&'.$params_unclassed : '' %>"
    168 class="context-menu-<% $class_name %>" title="Статус документа" data-id="<% $document->id %>"><img
    168 class="context-menu-<% $class_name %>" id="status-set-<% $document->id %>" title="Статус документа" data-id="<% $document->id %>"><img
    169 169 src="/contenido/i/actions/deactivate.gif" width="14" height="17" alt="Документ не активен" align="absmiddle" border="0" hspace="1"></a>\
    170 170 % }
    171 171 <br>\