Skip to content
This repository has been archived by the owner on Feb 15, 2019. It is now read-only.

Commit

Permalink
close to working description and youtube link
Browse files Browse the repository at this point in the history
  • Loading branch information
dessalines committed Sep 10, 2014
1 parent 7e265cf commit ad9af77
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 5 deletions.
9 changes: 6 additions & 3 deletions resources/testweb/creator_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ $(document).ready(function() {

simpleFetch('getcreatorpage').done(function(result) {
var jsonObj = JSON.parse(result);

var youtube_link = jsonObj['youtube_link'];
console.log('youtube ' + youtube_link);
$('#youtubeLinkInput').text(youtube_link);
if (youtube_link != null) {
$('#youtubeLinkInput').text(youtube_link);
}

var short_desc = jsonObj['description'];
console.log('short_desc ' + short_desc);
Expand All @@ -52,7 +55,7 @@ $(document).ready(function() {

}).on('success.form.bv', function(event) {
event.preventDefault();
alert('mmmk');
standardFormPost('save_youtube_link', "#youtubeLinkForm");
});

$('#shortDescriptionForm').bootstrapValidator({
Expand All @@ -62,7 +65,7 @@ $(document).ready(function() {

}).on('success.form.bv', function(event) {
event.preventDefault();
alert('mmmk2');
standardFormPost('save_creator_description', "#shortDescriptionForm");
});

}
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/com/bitpieces/shared/tools/WebCommon.java
Original file line number Diff line number Diff line change
Expand Up @@ -1314,6 +1314,52 @@ public static void commonPosts(Cache<String, UID> cache,
return message;

});

post("/save_youtube_link", (req, res) -> {
String message = null;
try {
WebCommon.allowResponseHeaders(req, res);
dbInit(prop);
UID cid = WebCommon.getUserFromCookie(req, cache, cookiePath);
cid.verifyCreator();



// get the creator id from the token
message = WebTools.saveCreatorYoutubeLink(cid.getId(), req.body());

dbClose();
}catch (NoSuchElementException e) {
e.printStackTrace();
}


return message;

});

post("/save_creator_description", (req, res) -> {
String message = null;
try {
WebCommon.allowResponseHeaders(req, res);
dbInit(prop);
UID cid = WebCommon.getUserFromCookie(req, cache, cookiePath);
cid.verifyCreator();



// get the creator id from the token
message = WebTools.saveCreatorDescription(cid.getId(), req.body());

dbClose();
}catch (NoSuchElementException e) {
e.printStackTrace();
}


return message;

});



Expand Down
49 changes: 47 additions & 2 deletions src/main/java/com/bitpieces/shared/tools/WebTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,53 @@ public static String saveCreatorPage(String id, String reqBody) {
page.set("main_body", reqBody).saveIt();
}

// Save the html page
// HTMLTools.saveCreatorHTMLPage(username, page);

return "Successful";

}

public static String saveCreatorYoutubeLink(String id, String reqBody) {

System.out.println(reqBody);
// Map<String, String> postMap = Tools.createMapFromAjaxPost(reqBody);

Creators_page_fields page = Creators_page_fields.findFirst("creators_id = ?", id);
Creator creator = Creator.findById(id);
String username = creator.getString("username");

// The first time filling the page fields
if (page == null) {
page = Creators_page_fields.createIt("creators_id", id,
"main_body", "Nothing here yet",
"youtube_link", reqBody);
} else {
page.set("youtube_link", reqBody).saveIt();
}


return "Successful";

}

public static String saveCreatorDescription(String id, String reqBody) {

System.out.println(reqBody);
// Map<String, String> postMap = Tools.createMapFromAjaxPost(reqBody);

Creators_page_fields page = Creators_page_fields.findFirst("creators_id = ?", id);
Creator creator = Creator.findById(id);
String username = creator.getString("username");

// The first time filling the page fields
if (page == null) {
page = Creators_page_fields.createIt("creators_id", id,
"main_body", "Nothing here yet",
"description", reqBody);
} else {
page.set("description", reqBody).saveIt();
}



return "Successful";

Expand Down

0 comments on commit ad9af77

Please sign in to comment.