Commit 38e41606cac6f1a0367af4f11324cb100776bf55

Authored by Karpikau Andrei
1 parent 086c6323

work on clone

@@ -156,32 +156,85 @@ jQuery(document).ready(function(){ @@ -156,32 +156,85 @@ jQuery(document).ready(function(){
156 156
157 }; 157 };
158 158
  159 + var getNextStructureIdGLobal = function($content_block){
  160 + var max_id = 0;
  161 + $content_block.find('.col, .row-element-block').each(function(){
  162 + var id = $(this).data('id');
  163 + if(id != undefined){
  164 + id = parseInt(id);
  165 + if(id > max_id){
  166 + max_id = id;
  167 + }
  168 + }
  169 +
  170 + });
  171 + max_id += 1;
  172 + return max_id;
  173 + }
  174 +
159 $('.html-generator').on('click', '.col-operation .col-duplicate, .row-operation .col-duplicate', function(){ 175 $('.html-generator').on('click', '.col-operation .col-duplicate, .row-operation .col-duplicate', function(){
160 var $this = $(this); 176 var $this = $(this);
161 177
162 - if($this.closest('.row-element-block').length > 0){  
163 - var $cell = $this.closest('.row-element-block');  
164 - }else{  
165 - var $cell = $this.closest('.col')  
166 - }  
167 - var id = $cell.data('id');  
168 - var $block = $cell.closest('.html-generator');  
169 - var duplicate_url = $block.data('duplicate-url'); 178 + if ($this.closest('.row-element-row').length > 0 && $this.closest('.col').length == 0){
  179 + var ids = [];
  180 + var $row = $this.closest('.row-element-row');
  181 + var $block = $row.closest('.html-generator');
  182 + var duplicate_url = $block.data('duplicate-url');
170 183
  184 + $this.closest('.row-element-row').find('.col').each(function(){
  185 + ids.push($(this).data('id'));
  186 + })
171 187
172 - jQuery.ajax({  
173 - type: 'POST',  
174 - url: duplicate_url,  
175 - data: {structure_id: id},  
176 - success: function (data) {  
177 - if(data.status == 'ok'){  
178 - var $newCell = $cell.clone();  
179 - $newCell.data('id', data.id);  
180 - $cell.after($newCell);  
181 - $block.find('.save').trigger('click'); 188 + jQuery.ajax({
  189 + type: 'POST',
  190 + url: duplicate_url,
  191 + data: {structure_ids: ids.join(',')},
  192 + success: function (data) {
  193 + if(data.status == 'ok'){
  194 + var $newRow = $row.clone(true);
  195 + $row.after($newRow);
  196 +
  197 + $newRow.find('.col').each(function(index){
  198 + if(data.ids[index] == ''){
  199 + $(this).data('id', getNextStructureIdGLobal($block.find('.html-content')));
  200 + }else{
  201 + $(this).data('id', data.ids[index]);
  202 + }
  203 + });
  204 +
  205 + $block.find('.save').trigger('click');
  206 + }
182 } 207 }
  208 + });
  209 + }else{
  210 + if($this.closest('.row-element-block').length > 0){
  211 + var $cell = $this.closest('.row-element-block');
  212 + }else{
  213 + var $cell = $this.closest('.col')
183 } 214 }
184 - }); 215 + var id = $cell.data('id');
  216 + var $block = $cell.closest('.html-generator');
  217 + var duplicate_url = $block.data('duplicate-url');
  218 +
  219 +
  220 + jQuery.ajax({
  221 + type: 'POST',
  222 + url: duplicate_url,
  223 + data: {structure_id: id},
  224 + success: function (data) {
  225 + if(data.status == 'ok'){
  226 + var $newCell = $cell.clone(true);
  227 + if(data.id == ''){
  228 + $newCell.data('id', getNextStructureIdGLobal($block.find('.html-content')));
  229 + }else{
  230 + $newCell.data('id', data.id);
  231 + }
  232 + $cell.after($newCell);
  233 + $block.find('.save').trigger('click');
  234 + }
  235 + }
  236 + });
  237 + }
185 238
186 return false; 239 return false;
187 }); 240 });
@@ -189,8 +242,8 @@ jQuery(document).ready(function(){ @@ -189,8 +242,8 @@ jQuery(document).ready(function(){
189 $('.html-generator').on('click', '.col-operation .col-disable, .row-operation .col-disable', function(){ 242 $('.html-generator').on('click', '.col-operation .col-disable, .row-operation .col-disable', function(){
190 var $this = $(this); 243 var $this = $(this);
191 244
192 - if($this.closest('.row-element-block').length > 0){  
193 - var $cell = $this.closest('.row-element-block'); 245 + if($this.closest('.row-element-block, .row-element-row').length > 0){
  246 + var $cell = $this.closest('.row-element-block, .row-element-row');
194 }else{ 247 }else{
195 var $cell = $this.closest('.col') 248 var $cell = $this.closest('.col')
196 } 249 }
@@ -458,9 +511,10 @@ jQuery(document).ready(function(){ @@ -458,9 +511,10 @@ jQuery(document).ready(function(){
458 '<div class="row-operation">' + 511 '<div class="row-operation">' +
459 '<a class="row-remove" href="javascript;void(0);"><i class="glyphicon glyphicon-trash"></i></a>'; 512 '<a class="row-remove" href="javascript;void(0);"><i class="glyphicon glyphicon-trash"></i></a>';
460 513
  514 + innerContent += '<a class="col-disable" href="javascript;void(0);"><i class="glyphicon '+ statusClass +'"></i></a>';
  515 + innerContent += '<a class="col-duplicate" href="javascript;void(0);"><i class="glyphicon glyphicon-file"></i></a>';
  516 +
461 if($(this).hasClass('row-element-block')) { 517 if($(this).hasClass('row-element-block')) {
462 - innerContent += '<a class="col-disable" href="javascript;void(0);"><i class="glyphicon '+ statusClass +'"></i></a>';  
463 - innerContent += '<a class="col-duplicate" href="javascript;void(0);"><i class="glyphicon glyphicon-file"></i></a>';  
464 innerContent += '<a class="col-content" href="javascript;void(0);"><i class="glyphicon glyphicon-pencil"></i></a>'; 518 innerContent += '<a class="col-content" href="javascript;void(0);"><i class="glyphicon glyphicon-pencil"></i></a>';
465 } 519 }
466 innerContent += '</div>' + 520 innerContent += '</div>' +
@@ -579,6 +633,8 @@ jQuery(document).ready(function(){ @@ -579,6 +633,8 @@ jQuery(document).ready(function(){
579 var $newContent = $('<div class="row-fluid row-element-row">' + 633 var $newContent = $('<div class="row-fluid row-element-row">' +
580 '<div class="row-inner">' + 634 '<div class="row-inner">' +
581 '<div class="row-operation">' + 635 '<div class="row-operation">' +
  636 + '<a class="col-disable" href="javascript;void(0);"><i class="glyphicon glyphicon-eye-open"></i></a>' +
  637 + '<a class="col-duplicate" href="javascript;void(0);"><i class="glyphicon glyphicon-file"></i></a>' +
582 '<a class="row-remove" href="javascript;void(0);"><i class="glyphicon glyphicon-trash"></i></a>' + 638 '<a class="row-remove" href="javascript;void(0);"><i class="glyphicon glyphicon-trash"></i></a>' +
583 '</div>' + 639 '</div>' +
584 '</div>' + 640 '</div>' +
@@ -630,14 +686,14 @@ jQuery(document).ready(function(){ @@ -630,14 +686,14 @@ jQuery(document).ready(function(){
630 if($row.hasClass('row-element-block')){ 686 if($row.hasClass('row-element-block')){
631 row_attributes['type'] = 'block'; 687 row_attributes['type'] = 'block';
632 row_attributes['id'] = $row.data('id'); 688 row_attributes['id'] = $row.data('id');
633 - if($row.data('status') == undefined || $row.data('status') == 'enabled'){  
634 - row_attributes['status'] = 'enabled';  
635 - }else{  
636 - row_attributes['status'] = 'disabled';  
637 - }  
638 }else{ 689 }else{
639 row_attributes['type'] = 'row'; 690 row_attributes['type'] = 'row';
640 } 691 }
  692 + if($row.data('status') == undefined || $row.data('status') == 'enabled'){
  693 + row_attributes['status'] = 'enabled';
  694 + }else{
  695 + row_attributes['status'] = 'disabled';
  696 + }
641 697
642 698
643 $row.find('.col').each(function(){ 699 $row.find('.col').each(function(){
@@ -124,22 +124,53 @@ module Kanjai @@ -124,22 +124,53 @@ module Kanjai
124 def duplicate_block 124 def duplicate_block
125 @page = Page.find(params[:id]) 125 @page = Page.find(params[:id])
126 @page_data = @page.page_data.find_by_lang(params[:lang]) 126 @page_data = @page.page_data.find_by_lang(params[:lang])
127 - @structure_id = params[:structure_id]  
128 - @obj = @page_data.page_contents.find_by_structure_id(@structure_id)  
129 - Page.transaction do  
130 - next_structure_id = @page_data.page_contents.pluck(:structure_id).max.to_i + 1  
131 - @new_obj = @obj.dup  
132 - @new_obj.structure_id = next_structure_id  
133 - @new_obj.save(validate: false)  
134 -  
135 - @obj.page_content_markers.each do |item|  
136 - new_item = item.dup  
137 - item.page_content = @new_obj  
138 - item.save(validate: false) 127 + if(params[:structure_ids].present?)
  128 + new_ids = []
  129 + params[:structure_ids].split(',').each do |structure_id|
  130 + next_structure_id = @page_data.page_contents.pluck(:structure_id).max.to_i + 1
  131 + @obj = @page_data.page_contents.find_by_structure_id(structure_id)
  132 + if @obj
  133 + @new_obj = @obj.dup
  134 + @new_obj.structure_id = next_structure_id
  135 + @new_obj.save(validate: false)
  136 +
  137 + @obj.page_content_markers.each do |item|
  138 + new_item = item.dup
  139 + item.page_content = @new_obj
  140 + item.save(validate: false)
  141 + end
  142 + new_ids << next_structure_id
  143 + else
  144 + new_ids << ''
  145 + end
139 end 146 end
140 -  
141 - render json: {status: 'ok', id: next_structure_id}  
142 - end 147 + render json: {status: 'ok', ids: new_ids}
  148 + else
  149 + @structure_id = params[:structure_id]
  150 + if @structure_id.to_i > 0
  151 + @obj = @page_data.page_contents.find_by_structure_id(@structure_id)
  152 + if @obj
  153 + Page.transaction do
  154 + next_structure_id = @page_data.page_contents.pluck(:structure_id).max.to_i + 1
  155 + @new_obj = @obj.dup
  156 + @new_obj.structure_id = next_structure_id
  157 + @new_obj.save(validate: false)
  158 +
  159 + @obj.page_content_markers.each do |item|
  160 + new_item = item.dup
  161 + item.page_content = @new_obj
  162 + item.save(validate: false)
  163 + end
  164 +
  165 + render json: {status: 'ok', id: next_structure_id}
  166 + end
  167 + else
  168 + render json: {status: 'ok', id: ''}
  169 + end
  170 + else
  171 + render json: {status: 'ok', id: ''}
  172 + end
  173 + end
143 end 174 end
144 175
145 def update_editor 176 def update_editor
@@ -105,27 +105,28 @@ module Kanjai @@ -105,27 +105,28 @@ module Kanjai
105 end 105 end
106 end 106 end
107 =end 107 =end
108 -  
109 - cells = ''  
110 - row["cells"].each do |cell|  
111 - if cell['status'].to_s == 'enabled' || cell['status'].to_s.empty?  
112 - page_content = page_data.page_contents.where(:structure_id => cell['id']).first  
113 - html_content = page_content.nil? ? '' : page_content.get_content_frontend  
114 - cell_class_name = cell['className']  
115 -  
116 - data_attributes = [  
117 - "data-size=#{cell['size']}",  
118 - "data-offset=#{cell['offset']}",  
119 - "data-id=#{cell['id']}",  
120 - "data-page_data_id=#{page_data.id}",  
121 - "data-class=#{cell['className']}",  
122 - ]  
123 -  
124 - cells += ApplicationController.render file: 'kanjai/pages/templates/cell', assigns: {content: html_content.html_safe, cell: cell, class_name: cell_class_name, data_attributes: data_attributes.join(' ')}, layout: false 108 + if row['attributes']['status'].to_s == 'enabled' || row['attributes']['status'].to_s.empty?
  109 + cells = ''
  110 + row["cells"].each do |cell|
  111 + if cell['status'].to_s == 'enabled' || cell['status'].to_s.empty?
  112 + page_content = page_data.page_contents.where(:structure_id => cell['id']).first
  113 + html_content = page_content.nil? ? '' : page_content.get_content_frontend
  114 + cell_class_name = cell['className']
  115 +
  116 + data_attributes = [
  117 + "data-size=#{cell['size']}",
  118 + "data-offset=#{cell['offset']}",
  119 + "data-id=#{cell['id']}",
  120 + "data-page_data_id=#{page_data.id}",
  121 + "data-class=#{cell['className']}",
  122 + ]
  123 +
  124 + cells += ApplicationController.render file: 'kanjai/pages/templates/cell', assigns: {content: html_content.html_safe, cell: cell, class_name: cell_class_name, data_attributes: data_attributes.join(' ')}, layout: false
  125 + end
125 end 126 end
126 - end  
127 127
128 - html += ApplicationController.render(file: 'kanjai/pages/templates/row', assigns: {content: cells.html_safe}, layout: false).html_safe 128 + html += ApplicationController.render(file: 'kanjai/pages/templates/row', assigns: {content: cells.html_safe}, layout: false).html_safe
  129 + end
129 130
130 end 131 end
131 132
@@ -76,13 +76,27 @@ module Kanjai @@ -76,13 +76,27 @@ module Kanjai
76 end 76 end
77 77
78 def clone 78 def clone
79 - new_page = self.deep_clone include: [:page_data]  
80 - new_page.save(validate: false)  
81 - new_page.page_data.each do |item|  
82 - item.title = "Copy #{item.title}"  
83 - item.save(validate: false) 79 + Page.transaction do
  80 + new_page = self.dup
  81 + new_page.save(validate: false)
  82 + self.page_data.each do |item|
  83 + new_item = item.dup
  84 + new_item.page = new_page
  85 + new_item.title = "Copy #{item.title}"
  86 + new_item.save(validate: false)
  87 + item.page_contents.each do |page_content|
  88 + new_page_content = page_content.dup
  89 + new_page_content.page_datum = new_item
  90 + new_page_content.save(validate: false)
  91 + page_content.page_content_markers.each do |page_content_marker|
  92 + new_page_content_marker = page_content_marker.dup
  93 + new_page_content_marker.page_content = new_page_content
  94 + new_page_content_marker.save(validate: false)
  95 + end
  96 + end
  97 + end
  98 + new_page.insert_at(self.position + 1)
84 end 99 end
85 - new_page.insert_at(self.position + 1)  
86 end 100 end
87 101
88 def self.default_public_page_url(scheme) 102 def self.default_public_page_url(scheme)
1 module Kanjai 1 module Kanjai
2 - VERSION = "0.0.136" 2 + VERSION = "0.0.137"
3 end 3 end