CHILD_DEL = 0 CHILD_ITEM = CHILD_DEL+1 CHILD_EDIT = CHILD_DEL+1 CHILD_EDIT_ITEM=CHILD_ITEM+1 CHILD_EDIT_ENTRY=CHILD_EDIT_ITEM+1 SUGGESTION_ACCEPT=0 SUGGESTION_REJECT=SUGGESTION_ACCEPT+1 SUGGESTION= SUGGESTION_REJECT+1 SUGGESTION_OWNER=SUGGESTION+1 SUGGESTION_CATEGORY=SUGGESTION_OWNER+1 jQuery -> hideMe({id:'forum-add-hyperlink-span'}) $('#forum-box').delegate 'input[id = delete-forum-object]','click', (evt) -> deleteForumObject(event.target) $('#forum-box').delegate 'input[id = edit-forum-object]','click', (evt) -> openEditObject(event.target) $('#forum-box').delegate 'input[id = forum-admin-button]','click', (evt) -> doButtonAction(event.target) event.stopPropagation() $('#forum-senate-admin-users').delegate '[id = forum-admin-list-option]','click', (evt) -> setSelections(event.target) $('#forum-category-admin').change -> getAdminsTopic() $('#forum-actions').change -> checkActionSetup(event.target) $('#forum-admin-language-select').change -> flipLanguage(event.target) $('#forum-actions').change -> handleActionChange(event.target) $('#forum-category-monitor').change -> monitorNewTopic() $('#restrict-category').click -> doRestrictCategory(event.target) $('#restrict-topic').click -> doRestrictTopic(event.target) #todo add reason selection for rejecion (forum and user privilages) doRestrictCategory=(button)-> if button.value== button.dataset.restrict button.value=button.dataset.submit showMe({id:'forum-restricted-list'}) else button.value= button.dataset.restrict hideMe({id:'forum-restricted-list'}) request={function:'forum admin action'} request.forum_action='restrict category' request.user_list=$('#forum-restricted-list').val() request.category=$('#forum-category-admin').val() $.post('xforum/forum_ajax',request) doRestrictTopic=(button)-> if button.value== button.dataset.restrict button.value=button.dataset.submit showMe({id:'forum-restricted-list'}) showMe({id:'forum-admin-topic'}) else button.value= button.dataset.restrict request={function:'forum admin action'} request.forum_action='restrict topic' request.category=$('#forum-topic-admin').val() request.user_list=$('#forum-restricted-list').val() hideMe({id:'forum-restricted-list'}) hideMe({id:'forum-admin-topic'}) $.post('xforum/forum_ajax',request) monitorNewTopic=-> select = document.getElementById('forum-category-monitor').value $.post('xforum/forum_ajax', {function: 'get topics',list:'forum-topic-monitor', category: select, hold_test: false, restricted: false}, loadList) getAdminCategory=-> document.getElementById('forum-category-admin').value handleActionChange=(which)-> switch which.value when 'send email to' showMe({id:"forum-email-email"}) else hideMe({id:"forum-email-email"}) doButtonAction = (which)-> switch(which.name) when 'forum-add-topic' addTopic(which,getAdminCategory(),'me') when 'review-forum' setUpReview(which) when 'forum-activate-language' turnLanguage('on') when 'forum-deactivate-language' turnLanguage('off') when 'forum-add-category' addCategory(which,'me') when 'forum-add-language' addLanguage(which,'me') when 'forum-translate-topic' translateList(which) when 'forum-translate-category' translateList(which) when 'forum-user-tag-choose' setTagView() when 'forum-user-email-choose' setEmailView() when 'forum-act-on-admin-selector' doAction() when 'forum-add-cancel' addCancel({obj:which}) when 'forum-admin-views' setAdminView(which) when 'forum-suggestion-response' handleSuggestionResponse(which) else window.doAdminStuff = -> document.getElementById('forum-senate').dataset.admining = 'true' setAdminDisplay() $.post('xforum/forum_ajax',{function:'get list',by_name:false, list:'admin-actions'},loadList) $.post('xforum/forum_ajax',{function:'get list',by_name:false, list:'forum-distribution-lists'},loadList) $.post('xforum/forum_ajax',{function:'get list',by_name:true, list:'admin-emails'},loadList) $.post('xforum/forum_ajax',{function:'get list',by_name:true, list:'admin-users'},loadList) $.post('xforum/forum_ajax',{function:'get list',by_name:false, list:'forum-restricted-list'},loadList) setAdminDisplay=-> hideMe({id: 'review-forum-span'}) hideMe({id: 'forum-senate'}) showMe({id: 'forum-senate-admin'}) hideMe({id: 'forum-user-tag-span'}) hideMe({id: 'forum-user-email-span'}) hideMe({id: 'forum-email-email'}) showMe({name: 'forum-user-email-show'}) hideMe({id:'forum-admin-topic'}) showMe({name: 'forum-user-tag-show'}) showMe({id:'forum-distribution-span'}) hideMe({id:'forum-moderator-add-span'}) hideMe({id:'forum-restricted-list'}) document.getElementById('forum-new-distribution-list').value='' turnLanguage=(toggle)-> showMe({id:'language-selector-span'}) $.post('xforum/forum_ajax',{function:'get language set',list:'forum-admin-language-select',active:toggle =='off'},loadList) setSelections = (which)-> if which.value == 'select none' hideMe({obj:which.parentNode.parentNode}) name=which.parentNode.name + '-show' showMe({name:name}) selections = getSelectValues({name:'forum-user-tag',ref:true}) selections= selections.concat(getSelectValues({name:'forum-user-email',ref:true})) selector= $('[name=forum-email-selections]') selector.children().remove() for i in [0...selections.length] unless selections[i]=='select none' pushOption(selector,{value:selections[i]}) setEmailView = -> blockMe({id:'forum-user-email-span'}) hideMe({name:'forum-user-email-show'}) $('#forum-user-email').focus() setMonitorView=-> hideMe({id:'forum-distribution-span'}) showMe({id:'forum-moderator-add-span'}) setDistributionListView=-> showMe({id:'forum-distribution-span'}) hideMe({id:'forum-moderator-add-span'}) setTagView = -> blockMe({id:'forum-user-tag-span'}) hideMe({name:'forum-user-tag-show'}) $('#user-tag').focus() checkActionSetup = (which)-> switch which.value when 'create distribution' setDistributionListView() when 'add topic monitor' setMonitorView() else flipLanguage=(selector)-> select = getSelectValues({obj:selector,ref:false}) $.post('xforum/forum_ajax',{function:'toggle language',language:select}) selector.selectedIndex=0 hideMe({id:'language-selector-span'}) doAction = -> request={} request.function = 'forum admin action' request.users1 = getSelectValues({name:'forum-user-tag',ref:false}) request.users2 = getSelectValues({name:'forum-user-email',ref:false}) request.subject = $('#forum-email-subject').val() request.body= $('#forum-email-body').val() request.topic=$('#forum-topic-monitor').val() $('#forum-email-body').val('') $('#forum-email-subject').val('') request.new_list_name = $('#forum-new-distribution-list').val() request.distribution_list = $('#forum-distribution-lists').val() request.forum_action = $('#forum-actions').val() document.getElementById('forum-actions').selectedIndex=0 setAdminDisplay() $("forum-email-body").val('') $.post('xforum/forum_ajax',request) setAdminView = (which_one)-> switch(which_one.dataset.view) when 'lists' blockMe({id:'forum-senate-admin-lists'}) hideMe({id:'forum-senate-admin-users'}) addCancel({name:'category'}) addCancel({name:'topic'}) addCancel({name:'language'}) $.post('xforum/forum_ajax',{function:'categories',list:'category', language:getLanguage(),hold_test:false,restricted:false},loadAdminsList) $.post('xforum/forum_ajax',{function:'get suggestions',list:'category'},loadForumSuggestions) $.post('xforum/forum_ajax',{function:'get suggestions',list:'topic'},loadForumSuggestions) $.post('xforum/forum_ajax',{function:'get suggestions',list:'language'},loadForumSuggestions) when 'users' hideMe({id:'forum-senate-admin-lists'}) blockMe({id:'forum-senate-admin-users'}) else setUpReview=(button)-> if button.dataset.state == 'done' showMe(id:'forum-review-buttons') button.dataset.state = 'review' clearSenate() $.post('xforum/forum_ajax', {function: 'get senate', topic: getTopic(), review: true}, setSenate) button.value = button.dataset.done else button.dataset.state = 'done' hideMe(id:'forum-review-buttons') button.value= button.dataset.review clearSenate deleteForumObject = (which_one)-> #id = which_one.dataset.target list=which_one.parentNode.parentNode.id $.post('xforum/forum_ajax',{function:'remove forum object',id:which_one.dataset.id,which_list:list,state_action:which_one.value}) if which_one.dataset.state == 'open' which_one.value = which_one.dataset.open which_one.dataset.state = 'closed' else which_one.value = which_one.dataset.del which_one.dataset.state= 'open' addOptionTo = (which_one,item)-> switch which_one when 'category' pushOption($('[name=category_admin]'),{item:item,value:item},0) pushOption($('[name=category]'),{item:item,value:item},2) when 'language' pushOption($('[name=language]'),{item:item,value:item},1) else translateList=(which)-> if which.dataset.state == 'done' translateSetup({obj:which}) else addCancel({obj:which}) addCategory = (which,user)-> if which.dataset.state == 'saved' addSetup({obj:which}) else new_category = $('#forum-add-admin-category').val() unless new_category == '' addListEntry('forum-admins-category-list',{item:new_category}) $.post('xforum/forum_ajax',{function:'add to list',list:'category',new_item:new_category,user:$('#forum-add-admin-user').val()}) addOptionTo('forum-category',new_category) addCancel({obj:which}) addLanguage = (which,user)-> if which.dataset.state == 'saved' addSetup({obj:which}) else new_language = $('#forum-add-admin-language').val() new_local = $('#forum-add-admin-language-localized').val() new_code = $('#forum-add-admin-language-code') unless new_language == '' addListEntry('forum-admins-language-list',{item:new_language}) $.post('xforum/forum_ajax',{function:'add to list',list:'language',language:new_language,local:new_local,code:new_code, user:$('#forum-add-admin-user').val()}) addCancel({obj:which}) addTopic=(which,category,user)-> if which.dataset.state == 'saved' addSetup({obj:which}) else new_topic = $('#forum-add-admin-topic').val() unless new_topic == '' addListEntry('forum-admins-topic-list',{item:new_topic,shift:true}) $.post('xforum/forum_ajax',{function:'add to list',list:'topic', topic:new_topic,category:category,user:$('#forum-add-admin-user').val()}) #addCancel({obj:which}) Don't know why this was here? Code copy addSetup=(params)-> if params.name == undefined params.name = params.obj.name.split('-')[2] params.obj.value = params.obj.dataset.save params.obj.dataset.state='adding' hideMe({name:"forum-translate-#{params.name}"}) $("input[data-who=#{params.name}]").show() #show cancel button showMe({id:"forum-add-#{params.name}-input-span"}) document.getElementById("forum-add-admin-#{params.name}").focus() translateSetup=(params)-> if params.name == undefined params.name = params.obj.name.split('-')[2] params.obj.value = params.obj.dataset.done params.obj.dataset.state='translating' document.getElementById('forum-admins-'+params.name+'-list').dataset.translating=true hideMe({name:"forum-add-#{params.name}"}) $("input[data-who=#{params.name}]").show() #show cancel button document.getElementById("forum-add-admin-#{params.name}").focus() addCancel=(params)-> if params.name == undefined if params.obj.dataset.who == undefined then params.name = params.obj.name.split('-')[2] else params.name = params.obj.dataset.who button = $("[name = forum-add-#{params.name}]").get()[0] button.dataset.state = 'saved' button.value = button.dataset.add unless params.name == 'language' button2= $("[name = forum-translate-#{params.name}]").get()[0] button2.dataset.state='done' button2.value= button2.dataset.translate showMe({obj:button2}) document.getElementById("forum-admins-#{params.name}-list").dataset.translating=false $("input[data-who=#{params.name}]").hide() hideMe({id:"forum-add-#{params.name}-input-span"}) showMe({obj:button}) showMe({name:"forum-add-#{params.name}"}) $("[id = forum-add-admin-#{params.name}]").val('') $("[id = forum-add-admin-user]").val('me') openEditObject = (which_one)-> id=which_one.dataset.id parent = which_one.parentNode line=parent.children[CHILD_EDIT_ENTRY].children[0] if which_one.dataset.state == 'edit' showMe({obj:parent.children[CHILD_EDIT_ENTRY]}) which_one.value = which_one.dataset.save which_one.dataset.state = 'save' line.value = parent.children[CHILD_EDIT_ITEM].innerHTML hideMe({obj:parent.children[CHILD_EDIT_ITEM]}) line.focus() else if which_one.dataset.state == 'save' which_one.dataset.state = 'edit' newline = line.value hideMe({obj:parent.children[CHILD_EDIT_ENTRY]}) showMe({obj:parent.children[CHILD_EDIT_ITEM]}) which_one.value = which_one.dataset.edit unless newline == '' translating=which_one.parentNode.parentElement.dataset.translating parent.children[CHILD_EDIT_ITEM].innerHTML = newline $.post('xforum/forum_ajax',{function:'edit forum object',id:id,newline:newline,which_list:which_one.parentNode.parentElement.id, translating:translating}) getAdminCategories = -> $.post('xforum/forum_ajax',{function:'get categories',category:select,language:getLanguage(),list,'category',hold_test:false,restriced:false},loadAdminsList) getAdminsTopic = -> select = document.getElementById('forum-category-admin').value $.post('xforum/forum_ajax',{function:'get topics',category:select,list:'topic',language:getLanguage(),hold_test:false,restricted:false},loadAdminsList) $.post('xforum/forum_ajax',{function:'get topics',category:select,list:'forum-admin-topic',language:getLanguage(),hold_test:false,restricted:false},loadList) window.loadAdminsList = (params)-> list_data = params.list_data switch params.id when 'topic' which = 'forum-admins-topic-list' short = 0 shift = true when 'category' which = 'forum-admins-category-list' short = 1 shift = true else alist = document.getElementById(which).children dummy = alist[0] if dummy? for i in [1...alist.length] removeMe({obj:document.getElementById(which).children[1]}) if list_data.length>0 for i in [0...list_data.length-short] vars = list_data[i] vars.inert = i == 0||i == list_data.length-1-short vars.shift = shift if list_data[i].state? vars.state = list_data[i].state addListEntry(which,vars) removeMe({obj:dummy}) else id = dummy.children[0].dataset.target document.getElementById(id).innerHTML = '' addListEntry = (which,vars)-> entry = document.getElementById(which).children[0].cloneNode(true) i = document.getElementById(which).children.length ref = document.getElementById(which).children[i-1] tag = which.split('-')[1] entry.children[CHILD_DEL].dataset.id = vars.id entry.children[CHILD_DEL].dataset.target = 'list-item-'+tag+'-'+i if vars.inert $(entry.children[CHILD_DEL]).val('----') else entry.children[CHILD_DEL].id = 'delete-forum-object' entry.children[CHILD_DEL].value= entry.children[CHILD_DEL].dataset.del entry.children[CHILD_EDIT].dataset.id = vars.id entry.children[CHILD_EDIT].dataset.target = 'list-item-'+tag+'-'+i entry.children[CHILD_EDIT].dataset.state = 'edit' entry.children[CHILD_EDIT_ITEM].innerHTML = vars.item entry.children[CHILD_EDIT_ITEM].id = 'list-item-'+tag+'-'+i entry.children[CHILD_EDIT_ENTRY].children[0].id="edit-entry-#{vars.id}" item=CHILD_EDIT_ITEM if vars.closed entry.children[item].className = 'forum-closed' entry.children[CHILD_DEL].value = entry.children[CHILD_DEL].dataset.open entry.children[CHILD_DEL].dataset.state = 'closed' else entry.children[CHILD_DEL].dataset.state = 'open' document.getElementById(which).insertBefore(entry,ref) loadForumSuggestions = (params)-> unless !params? || params.data.length == 0 list = document.getElementById(params.list) for i in [0...params.data.length] pushElement(list,params.data[i],params.list) removeMe({obj:list.children[0]}) pushElement = (list,data,which)-> entry = list.children[0].cloneNode(true) entry.id = 'list-' + which.split('-')[0]+ list.children.length entry.dataset.the_id = data.id entry.children[SUGGESTION_ACCEPT].dataset.id = list.children.length entry.children[SUGGESTION_REJECT].dataset.id = list.children.length entry.children[SUGGESTION].id = which.split('-')[1]+ '-item-'+ list.children.length entry.children[SUGGESTION_OWNER].id = which.split('-')[1]+ '-user-'+ list.children.length entry.children[SUGGESTION].innerHTML = data.suggestion entry.children[SUGGESTION_OWNER].innerHTML = " |"+data.user+"| " if data.category? entry.children[SUGGESTION_CATEGORY].innerHTML = data.category entry.children[SUGGESTION_CATEGORY].id = which.split('-')[1]+ '-category-'+ list.children.length list.appendChild(entry) handleSuggestionResponse = (which_one)-> if which_one.value == 'Accept' id = which_one.dataset.id which_one.dataset.state='save' switch which_one.parentNode.parentElement.id when 'forum-category-prososals-list' user=$("span[id = category-user-#{id}]").get()[0].innerHTML.split('|')[1] $('#forum-add-admin-category').val($("span[id = category-item-#{id}]").get()[0].innerHTML) $('#forum-add-admin-user').val(user) addCategory(which_one,user) when 'forum-topic-prososals-list' topic=$('span[id = topic-item-'+id+']').get()[0].innerHTML user= $("span[id =topic-user-#{id}]").get()[0].innerHTML.split('|')[1] $('#forum-add-admin-topic').val(topic) $('#forum-add-admin-user').val(user) category= $('span[id = topic-category-'+id+']').get()[0].innerHTML.trim() addTopic(which_one,category,user) when 'forum-language-proposal-list' $('#forum-aadd-admin-language').val($("span[id = language-item-#{id}]").get()[0].innerHTML) $('#forum-add-admin-user').val($("span[id = language-user-#{id}]").get()[0].innerHTML.split('|')[1]) user= $("span[id = language-user-#{id}]").get()[0].innerHTML.split('|')[1] addLanguage(which_one,user) else closeListItem(which_one) closeListItem = (which_one)-> id = which_one.parentNode.dataset.the_id $.post('xforum/forum_ajax',{function:'suggestion close',id:id,result:which_one.value,list:which_one.parentNode.parentElement.id}) if which_one.parentNode.parentElement.children.length == 1 which_one.parentNode.parentElement.style.display = 'none' else removeIt(which_one.parentNode)