| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- "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");
- }
- _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);
|