"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 = $('
  • ' + example.title + '
  • ') // .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"); } _ws.makeView('add-repo-form', { render: function() { console.log('render form add repo', this); this.$elem.addClass('in'); this.$btn.removeClass('in'); this.$elem.find('input[name="title"]').focus(); }, $btn: $('#add-repo-btn'), events: { 'click .icon-cross': function() { this.$elem.removeClass('in'); this.$btn.addClass('in'); }, 'submit': function(e) { e.preventDefault(); console.log('submit form'); } } }); 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);