Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
Add doc and fix fragment remove issue
Browse files Browse the repository at this point in the history
  • Loading branch information
qsomazzi committed Dec 2, 2016
1 parent 5dc93e3 commit dc1f17e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 16 deletions.
1 change: 1 addition & 0 deletions Resources/doc/index.rst
Expand Up @@ -14,3 +14,4 @@ Reference Guide
reference/getting_started
reference/configuration
reference/custom_fragment
reference/todo
11 changes: 11 additions & 0 deletions Resources/doc/reference/todo.rst
@@ -0,0 +1,11 @@
Todo
====

This bundle is still a work in progress, we need to work more on some part.
We will try to keep this "Todo list" up to date to inform you of our expectations.

- Find a better way to handle fragment validation
- Add articleTranslation feature (each articles are translatable and related to a Site)
- Publishing Workflow
- Handle formats (web, json, ...)
- Duplicate article
60 changes: 44 additions & 16 deletions Resources/public/js/fragmentList.jquery.js
@@ -1,4 +1,4 @@
(function ($, window, document, undefined) {
(function($) {
// Create the defaults once
var pluginName = 'fragmentList',
defaults = {
Expand All @@ -23,6 +23,7 @@
this.options = $.extend({}, defaults, options) ;
this._defaults = defaults;
this._name = pluginName;
this._elementsIndex = 0;
this.init();
}

Expand Down Expand Up @@ -90,10 +91,29 @@
// Before adding, be sure the current fragment is valid
if(!this.checkValidity()) return;

if (this._elementsIndex === 0) {
var maxIndex = 0;

this.$list.children().each(function(i, child) {
var fragId = $(child).data('frag-id');
fragId = fragId.split('_');
var fragmentId = fragId.length > 0 ? fragId[fragId.length - 1] : null;

if (!isNaN(fragmentId) && fragmentId > maxIndex) {
maxIndex = parseInt(fragmentId);
}
});

this._elementsIndex = maxIndex;
}

this._elementsIndex++;
Admin.log('[fragments|add] current index is ' + this._elementsIndex);

// Submit the new fragment
var self = this;
jQuery(this.$form).ajaxSubmit({
url: this.options.getAddUrl(this.$list.children().length),
url: this.options.getAddUrl(this._elementsIndex),
type: 'POST',
dataType: 'html',
data: { _xml_http_request: true },
Expand Down Expand Up @@ -134,21 +154,25 @@
e.preventDefault();
e.stopPropagation();

// @todo : translate this
if (!confirm("The fragment will be deleted after update. Are you sure?")) {
return;
}

var $target = $(e.currentTarget),
$frag = $target.closest('[data-fragment]'),
id = $frag.data('fragId'),
$form = this.getFormByFragmentId(id),
$cb = $form.find(this.options.formRemoveName);

// Remove a persisted fragment (just check delete checkbox)
if($form.data('formTmp')) {
if (!$frag.hasClass('is-tmp')) {
// Check the delete checkbox
$cb.prop('checked', true).attr('checked', true);
console.log($form.find(this.options.formRemoveName));

// Hide form block
$form.hide();
// Remove a new fragment (not already saved)
// Remove a new fragment (not already saved)
} else {
$form.remove();
this.setFormListElement();
Expand All @@ -160,7 +184,7 @@
// Removed the last element ?
if(!this.$list.children().length) {
this.$activeFragment = null;
// Removed the current visible item ?
// Removed the current visible item ?
} else if(id === this.$activeFragment.data('fragId')) {
this.setActive(this.$list.children(':first-child'));
}
Expand Down Expand Up @@ -325,13 +349,17 @@
}
};

// A really lightweight plugin wrapper around the constructor,
// preventing against multiple instantiations
$.fn[pluginName] = function ( options ) {
return this.each(function () {
if (!$.data(this, 'plugin_' + pluginName)) {
$.data(this, 'plugin_' + pluginName, new Plugin(this, options));
}
});
};
})(jQuery, window, document);
$(document).ready(function() {

// A really lightweight plugin wrapper around the constructor,
// preventing against multiple instantiations
$.fn[pluginName] = function ( options ) {
return this.each(function () {
if (!$.data(this, 'plugin_' + pluginName)) {
$.data(this, 'plugin_' + pluginName, new Plugin(this, options));
}
});
};

});
})(jQuery);

0 comments on commit dc1f17e

Please sign in to comment.