|
|
@@ -45,7 +45,46 @@
|
|
|
// }
|
|
|
|
|
|
|
|
|
- function makeFormView(elemId, onSubmitPromise) {
|
|
|
+ function makeFormView(elemId, onSubmitPromise, options) {
|
|
|
+
|
|
|
+ // Fallback options & options.events
|
|
|
+ options = options || {};
|
|
|
+ options.events = options.events || {};
|
|
|
+
|
|
|
+ // Define events and optionally extend them with those
|
|
|
+ // provided in options.events
|
|
|
+ var events = Object.assign({
|
|
|
+ 'click .add-btn': function() {
|
|
|
+ this.render();
|
|
|
+ },
|
|
|
+
|
|
|
+ 'click .icon-cross': function() {
|
|
|
+ this.$form.removeClass('in');
|
|
|
+ this.$btn.addClass('in');
|
|
|
+ },
|
|
|
+
|
|
|
+ 'submit form': function(e) {
|
|
|
+ e.preventDefault();
|
|
|
+ if(this.cantSubmit) {
|
|
|
+ this.$input
|
|
|
+ .removeClass('input-success input-warning')
|
|
|
+ .addClass('input-error');
|
|
|
+ _ws.notify('error', this.cantSubmit);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var title = this.$input.val();
|
|
|
+ // rp.post('/collections', { title: title })
|
|
|
+ onSubmitPromise(title)
|
|
|
+ .then(function(c) {
|
|
|
+ _ws.notify('success', 'Collection créée: ' + c.title);
|
|
|
+ })
|
|
|
+ .catch(function(err) {
|
|
|
+ console.error(err);
|
|
|
+ _ws.notify('error', 'Impossible de créer la collection: ' + err.message);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }, options.events);
|
|
|
+
|
|
|
_ws.makeView(elemId, {
|
|
|
|
|
|
init: function() {
|
|
|
@@ -62,30 +101,7 @@
|
|
|
this.$input.focus();
|
|
|
},
|
|
|
|
|
|
- events: {
|
|
|
- 'click .add-btn': function() {
|
|
|
- this.render();
|
|
|
- },
|
|
|
-
|
|
|
- 'click .icon-cross': function() {
|
|
|
- this.$form.removeClass('in');
|
|
|
- this.$btn.addClass('in');
|
|
|
- },
|
|
|
-
|
|
|
- 'submit form': function(e) {
|
|
|
- e.preventDefault();
|
|
|
- var title = this.$input.val();
|
|
|
- // rp.post('/collections', { title: title })
|
|
|
- onSubmitPromise(title)
|
|
|
- .then(function(c) {
|
|
|
- _ws.notify('success', 'Collection créée: ' + c.title);
|
|
|
- })
|
|
|
- .catch(function(err) {
|
|
|
- console.error(err);
|
|
|
- _ws.notify('error', 'Impossible de créer la collection: ' + err.message);
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
+ events: events
|
|
|
|
|
|
});
|
|
|
}
|
|
|
@@ -99,6 +115,45 @@
|
|
|
});
|
|
|
|
|
|
|
|
|
+ makeFormView(
|
|
|
+ 'add-file',
|
|
|
+ function(name) {
|
|
|
+ return rp.post('/' + _ws.repo.path + '/examples/file', { name: name });
|
|
|
+ },
|
|
|
+ {
|
|
|
+ events: {
|
|
|
+ 'keyup input[name="title"]': function(e) {
|
|
|
+ var filename = this.$input.val();
|
|
|
+ // console.log('filename', filename);
|
|
|
+ var bits = filename.split('.');
|
|
|
+ var lastIdx = bits.length - 1;
|
|
|
+ console.log(bits, bits.length, lastIdx, bits[lastIdx], typeof bits[lastIdx]);
|
|
|
+ if(bits.length < 2) {
|
|
|
+ this.$input
|
|
|
+ .removeClass('input-success input-error')
|
|
|
+ .addClass('input-warning');
|
|
|
+ this.cantSubmit = 'Impossible de valider: extension (.html/.js/.css) manquante';
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ var ext = (bits[lastIdx]).toLowerCase();
|
|
|
+ console.log(ext);
|
|
|
+ if( ['html', 'js', 'css'].indexOf( ext ) === -1 ) {
|
|
|
+ this.$input
|
|
|
+ .removeClass('input-success input-warning')
|
|
|
+ .addClass('input-error');
|
|
|
+ this.cantSubmit = 'Impossible de valider: extension ' + ext + ' invalide (autorisées: .html/.js/.css)';
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.$input.addClass('input-success');
|
|
|
+ this.cantSubmit = undefined;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
|
|
|
console.log(_ws.ui);
|
|
|
|