<% wikitoolbar = @easy_page_modules_data[block_name][:wikitoolbar] %>
<fieldset>
  <div class="clear">
    <p class="floating">
      <%= label_tag "#{block_name}_heading", l(:label_heading) %>
      <%= text_field_tag "#{block_name}[heading]", settings['heading'] || l('easy_pages.modules.noticeboard') %>
    </p>
  </div>

  <div class="wikitoolbar-wrap">
    <%= text_area_tag "#{block_name}[text]", settings['text'], cols: 60, rows: 10, class: 'wiki-edit' %>
    <%= wikitoolbar_for("#{block_name}_text", toolbar: wikitoolbar) %>
  </div>
</fieldset>

<script type="text/javascript">
  $(function(){
    if (typeof CKEDITOR !== 'undefined') {
      var saved_text_<%= page_module.uuid.underscore %> = '',
          ckeditor_id = '<%= block_name.underscore %>_text',
          ckeditor_instance = CKEDITOR.instances[ckeditor_id];

      draggable_onstart_module_<%= page_module.uuid.underscore %> = function(draggable, event) {
        saved_text_<%= page_module.uuid.underscore %> = ckeditor_instance.getData();
      };
      draggable_onend_module_<%= page_module.uuid.underscore %> = function(draggable, event) {
        ckeditor_config = ckeditor_instance.config;
        CKEDITOR.remove(ckeditor_instance);
        $('cke_<%= block_name.underscore %>_text').remove();
        $('<%= block_name.underscore %>_text').value = saved_text_<%= page_module.uuid.underscore %>;
        CKEDITOR.replace(ckeditor_id, ckeditor_config);
      };
    }
  });
</script>
