Fix export snippet should check data before sending request and fix some code styles

This commit is contained in:
Cheng-Han, Wu 2016-05-15 13:01:41 +08:00
parent aa34faf8ab
commit 9e75c5cdf4
3 changed files with 11 additions and 13 deletions

View file

@ -1202,7 +1202,7 @@ ui.toolbar.export.snippet.click(function() {
} }
$('<option>').val(project.id).text(project.path_with_namespace).appendTo("#snippetExportModalProjects"); $('<option>').val(project.id).text(project.path_with_namespace).appendTo("#snippetExportModalProjects");
}); });
$("#snippetExportModalProjects").prop('disabled',false); $("#snippetExportModalProjects").prop('disabled', false);
} }
$("#snippetExportModalLoading").hide(); $("#snippetExportModalLoading").hide();
}) })
@ -1212,7 +1212,6 @@ ui.toolbar.export.snippet.click(function() {
.complete(function () { .complete(function () {
ui.spinner.hide(); ui.spinner.hide();
}); });
return false;
}); });
//import from dropbox //import from dropbox
ui.toolbar.import.dropbox.click(function () { ui.toolbar.import.dropbox.click(function () {
@ -1291,7 +1290,7 @@ ui.toolbar.import.snippet.click(function () {
} }
$('<option>').val(project.id).text(project.path_with_namespace).appendTo("#snippetImportModalProjects"); $('<option>').val(project.id).text(project.path_with_namespace).appendTo("#snippetImportModalProjects");
}); });
$("#snippetImportModalProjects").prop('disabled',false); $("#snippetImportModalProjects").prop('disabled', false);
} }
$("#snippetImportModalLoading").hide(); $("#snippetImportModalLoading").hide();
}) })
@ -1301,7 +1300,6 @@ ui.toolbar.import.snippet.click(function () {
.complete(function () { .complete(function () {
ui.spinner.hide(); ui.spinner.hide();
}); });
return false;
}); });
//import from clipboard //import from clipboard
ui.toolbar.import.clipboard.click(function () { ui.toolbar.import.clipboard.click(function () {
@ -1340,7 +1338,7 @@ ui.modal.snippetImportProjects.change(function() {
$('<option>').val(snippet.id).text(snippet.title).appendTo($("#snippetImportModalSnippets")); $('<option>').val(snippet.id).text(snippet.title).appendTo($("#snippetImportModalSnippets"));
}); });
$("#snippetImportModalLoading").hide(); $("#snippetImportModalLoading").hide();
$("#snippetImportModalSnippets").prop('disabled',false); $("#snippetImportModalSnippets").prop('disabled', false);
}) })
.error(function(err) { .error(function(err) {
@ -1508,7 +1506,7 @@ $("#snippetImportModalClear").click(function () {
$("#snippetImportModalContent").val(''); $("#snippetImportModalContent").val('');
$("#snippetImportModalProjects").val('init'); $("#snippetImportModalProjects").val('init');
$("#snippetImportModalSnippets").val('init'); $("#snippetImportModalSnippets").val('init');
$("#snippetImportModalSnippets").prop('disabled',true); $("#snippetImportModalSnippets").prop('disabled', true);
}); });
$("#snippetImportModalConfirm").click(function () { $("#snippetImportModalConfirm").click(function () {
var snippeturl = $("#snippetImportModalContent").val(); var snippeturl = $("#snippetImportModalContent").val();
@ -1563,7 +1561,7 @@ $("#snippetExportModalConfirm").click(function() {
code: editor.getValue(), code: editor.getValue(),
visibility_level: $("#snippetExportModalVisibility").val() visibility_level: $("#snippetExportModalVisibility").val()
}; };
if (!data.title || !data.file_name || !data.code || !data.visibility_level || !$("#snippetExportModalProjects").val()) return;
$("#snippetExportModalLoading").show(); $("#snippetExportModalLoading").show();
var fullURL = baseURL + '/api/v3/projects/' + $("#snippetExportModalProjects").val() + '/snippets?access_token=' + accesstoken; var fullURL = baseURL + '/api/v3/projects/' + $("#snippetExportModalProjects").val() + '/snippets?access_token=' + accesstoken;
$.post(fullURL $.post(fullURL

View file

@ -181,7 +181,7 @@
<input type="url" class="form-control" placeholder="/projects/:id/snippets/:snippet_id" id="snippetImportModalContent" disabled="disabled"> <input type="url" class="form-control" placeholder="/projects/:id/snippets/:snippet_id" id="snippetImportModalContent" disabled="disabled">
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<span id="snippetImportModalLoading"><i class="fa fa-refresh fa-spin"></i></span> <span id="snippetImportModalLoading"><i class="fa fa-refresh fa-spin fa-fw"></i></span>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button> <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-danger" id="snippetImportModalClear">Clear</button> <button type="button" class="btn btn-danger" id="snippetImportModalClear">Clear</button>
<button type="button" class="btn btn-primary" id="snippetImportModalConfirm" disabled="disabled">Import</button> <button type="button" class="btn btn-primary" id="snippetImportModalConfirm" disabled="disabled">Import</button>
@ -227,7 +227,7 @@
</div> </div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<span id="snippetExportModalLoading"><i class="fa fa-refresh fa-spin"></i></span> <span id="snippetExportModalLoading"><i class="fa fa-refresh fa-spin fa-fw"></i></span>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button> <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" id="snippetExportModalConfirm">Export</button> <button type="button" class="btn btn-primary" id="snippetExportModalConfirm">Export</button>
</div> </div>

View file

@ -43,7 +43,7 @@
</li> </li>
<% } %> <% } %>
<% if(typeof gitlab !== 'undefined' && gitlab) { %> <% if(typeof gitlab !== 'undefined' && gitlab) { %>
<li role="presentation"><a role="menuitem" class="ui-save-snippet" href="#" data-toggle="modal" data-target="#snippetExportModal"><i class="fa fa-gitlab fa-fw"></i> Snippet</a> <li role="presentation"><a role="menuitem" class="ui-save-snippet" href="#"><i class="fa fa-gitlab fa-fw"></i> Snippet</a>
</li> </li>
<% } %> <% } %>
<li class="divider"></li> <li class="divider"></li>
@ -55,7 +55,7 @@
<li role="presentation"><a role="menuitem" class="ui-import-gist" href="#" data-toggle="modal" data-target="#gistImportModal"><i class="fa fa-github fa-fw"></i> Gist</a> <li role="presentation"><a role="menuitem" class="ui-import-gist" href="#" data-toggle="modal" data-target="#gistImportModal"><i class="fa fa-github fa-fw"></i> Gist</a>
</li> </li>
<% if(typeof gitlab !== 'undefined' && gitlab) { %> <% if(typeof gitlab !== 'undefined' && gitlab) { %>
<li role="presentation"><a role="menuitem" class="ui-import-snippet" href="#" data-toggle="modal" data-target="#snippetImportModal"><i class="fa fa-gitlab fa-fw"></i> Snippet</a> <li role="presentation"><a role="menuitem" class="ui-import-snippet" href="#"><i class="fa fa-gitlab fa-fw"></i> Snippet</a>
</li> </li>
<% } %> <% } %>
<li role="presentation"><a role="menuitem" class="ui-import-clipboard" href="#" data-toggle="modal" data-target="#clipboardModal"><i class="fa fa-clipboard fa-fw"></i> Clipboard</a> <li role="presentation"><a role="menuitem" class="ui-import-clipboard" href="#" data-toggle="modal" data-target="#clipboardModal"><i class="fa fa-clipboard fa-fw"></i> Clipboard</a>
@ -136,7 +136,7 @@
</li> </li>
<% } %> <% } %>
<% if(typeof gitlab !== 'undefined' && gitlab) { %> <% if(typeof gitlab !== 'undefined' && gitlab) { %>
<li role="presentation"><a role="menuitem" class="ui-save-snippet" href="#" data-toggle="modal" data-target="#snippetExportModal"><i class="fa fa-gitlab fa-fw"></i> Snippet</a> <li role="presentation"><a role="menuitem" class="ui-save-snippet" href="#"><i class="fa fa-gitlab fa-fw"></i> Snippet</a>
</li> </li>
<% } %> <% } %>
<li class="divider"></li> <li class="divider"></li>
@ -148,7 +148,7 @@
<li role="presentation"><a role="menuitem" class="ui-import-gist" href="#" data-toggle="modal" data-target="#gistImportModal"><i class="fa fa-github fa-fw"></i> Gist</a> <li role="presentation"><a role="menuitem" class="ui-import-gist" href="#" data-toggle="modal" data-target="#gistImportModal"><i class="fa fa-github fa-fw"></i> Gist</a>
</li> </li>
<% if(typeof gitlab !== 'undefined' && gitlab) { %> <% if(typeof gitlab !== 'undefined' && gitlab) { %>
<li role="presentation"><a role="menuitem" class="ui-import-snippet" href="#" data-toggle="modal" data-target="#snippetImportModal"><i class="fa fa-gitlab fa-fw"></i> Snippet</a> <li role="presentation"><a role="menuitem" class="ui-import-snippet" href="#"><i class="fa fa-gitlab fa-fw"></i> Snippet</a>
</li> </li>
<% } %> <% } %>
<li role="presentation"><a role="menuitem" class="ui-import-clipboard" href="#" data-toggle="modal" data-target="#clipboardModal"><i class="fa fa-clipboard fa-fw"></i> Clipboard</a> <li role="presentation"><a role="menuitem" class="ui-import-clipboard" href="#" data-toggle="modal" data-target="#clipboardModal"><i class="fa fa-clipboard fa-fw"></i> Clipboard</a>