| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- "use strict";
- (function($) {
- $(document).ready(function() {
- // var $addRepoBtn = $('#add-repo-btn');
- // var $addExampleBtn = $('#add-example-btn');
- // var $exampleForm = $('#add-example-form');
- // var $exampleFormIn = $exampleForm.find('input');
- // var $exampleSave = $('#add-example-save');
- // var $exampleCancel = $('#add-example-cancel');
- // /**
- // * Add new example
- // */
- // function addExample(e) {
- // e.preventDefault();
- // var repoSlug = $detailsRepo.data('slug');
- // var title = $(this).find('input[name="title"]').val();
- // rp.post('/' + repoSlug + '/examples', { title: title })
- // .then(function(example) {
- // clearAndCloseEditor();
- // // $fileSelect.append(makeFileSelectOption(example));
- // // $fileSelect.val(example.slug);
-
- // // var $exMenuItem = $('<li><a href="/' + repoSlug + '/' + example.slug + '">' + example.title + '</a></li>')
- // // .appendTo( $('#cat-' + example.category) );
- // notify('success', "Exemple créé !");
- // // navigateTo('/'+ repoSlug + '/' + example.slug);
- // })
- // .catch(errText => notify('error', 'Erreur: ' + errText));
- // }
- // function clearAndCloseEditor() {
- // $exampleFormIn.val('');
- // toggleEditor();
- // }
- // function toggleEditor() {
- // $addExampleBtn.toggle();
- // $exampleForm.toggleClass("hidden");
- // }
- function makeFormView(elemId, onSubmitPromise) {
- _ws.makeView(elemId, {
- init: function() {
- this.$btn = this.$elem.find('.add-btn');
- this.$form = this.$elem.find('form');
- this.$input = this.$form.find('input[name="title"]');
- console.log('init add repo form', this.$elem.prop('id'))
- },
- render: function() {
- console.log('render form add ', this.$elem.prop('id'));
- this.$btn.removeClass('in');
- this.$form.addClass('in');
- 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);
- });
- }
- }
- });
- }
- makeFormView('add-repo', function(title) {
- return rp.post('/repos', { title: title });
- });
- makeFormView('add-example', function(title) {
- return rp.post('/' + _ws.repo.path + '/examples', { title: title });
- });
- console.log(_ws.ui);
- // _ws.ui.addRepoForm.$btn.click(_ws.ui.addRepoForm.render);
- // console.log($addExampleBtn);
- // $addExampleBtn.click(toggleEditor);
- // $exampleCancel.click(clearAndCloseEditor);
- // $exampleForm.submit(addExample);
- });
- })(jQuery);
|