var comments = {} comments.show = function(thread_id) { document.write('
' c += '
'; c += ''; c += ''; c += ''; c += '
'; c += '
'; c += '
'; var elem = $(c); elem.find('.name').text(comment.name); if (comment.email) { elem.find('.email').text('<'+comment.name+'>'); } elem.find('.posted').text(comment.created); elem.find('.message').text(comment.message); target.append(elem); } var form = '
'; form += '
'; form += '
'; form += ''; form += '
'; form += ''; form += ''; form += '*'; form += ''; form += ''; form += ''; form += ''; form += ''; form += '
'; form += '
'; form += ''; form += ''; form += '
'; form += '
'; form += '
'; target.append(form); } $.getJSON(cserv.baseuri+'/comment/list/json/'+thread_id+'/?jsonp=?', success); } cserv.post = function(target) { //validation var form = $('#post'); var param = { 'thread_id': form.find('input[name="thread_id"]').val(), 'name': form.find('input[name="name"]').val(), 'email': form.find('input[name="email"]').val(), 'message': form.find('input[name="message"]').val() } var errors = $('#form_error'); errors.empty(); var success = function(data, stat) { if (!('stat' in data) || data['stat'] != 'ok') { if ('errors' in data) { var msg = 'エラーメッセージ'; msg += ""; errors.append(msg); } return; } cserv.show_thread(param['thread_id'],target); } cserv.callAPI('/comment/post', param, success); } cserv.callAPI = function(method, param, success) { if (cserv.baseuri.indexOf('http') == 0) { $.getJSON(cserv.baseuri+method+'?jsonp=?', param, success, 'json'); } else { $.post(cserv.baseuri+method, param, success, 'json'); } } var question = {} question.html = { active: '', posted: '' } question.post_answer = function(question_id, order, callback) { var success = function(data, stat) { if (data && 'stat' in data && (data['stat'] == 'ok' || data['stat'] == 'duplicated')) { callback(); } } var param = { question_id: question_id, order: order } cserv.callAPI('/question/post', param, success); return false; } question.show_button = function(q) { for (var i=0; i < q['answers'].length; i++) { var answer = q['answers'][i]; var button = $('#'+q['id'].replace('.','\\.')+'_'+answer['order']); if (answer['posted']) { button.html(question.html.posted); } else { button.html(question.html.active); button.click(function() { var elem = $(this); var id = elem.attr('id'); var question_id = id.substring(0,id.lastIndexOf('_')) var order = id.substring(id.lastIndexOf('_')+1) var callback = function() { elem.html(question.html.posted); } question.post_answer(question_id, order, callback); }); } } } question.load_answers = function(question_id) { var success = function(data, stat) { if (data && 'stat' in data && data['stat'] == 'ok') { question.show_button(data['question']); } } cserv.callAPI('/question/'+question_id, {}, success); }