Commit 259970ca authored by Arinde Eniola's avatar Arinde Eniola

abstract code for removing or getting a param query string from url

parent ef9f5579
......@@ -36,20 +36,6 @@
$(".selected_issue").bind "change", Issues.checkChanged
getLabelsQueryString: ->
pageURL = decodeURIComponent(window.location.search.substring(1))
urlVariables = pageURL.split('&')
labelParams = (
variables for variables in urlVariables when variables.indexOf('label_name[]') > -1
).join('&')
removeLabelsQueryString: (url) ->
pageURL = decodeURIComponent(url)
urlVariables = pageURL.split('&')
Params = (
variables for variables in urlVariables when variables.indexOf('label_name[]') is -1
).join('&')
# Update state filters if present in page
updateStateFilters: ->
stateFilters = $('.issues-state-filters')
......@@ -61,9 +47,9 @@
if stateFilters.length
stateFilters.find('a').each ->
initialUrl = Issues.removeLabelsQueryString($(this).attr 'href')
if Issues.getLabelsQueryString()
newUrl = "#{gl.utils.mergeUrlParams(newParams, initialUrl)}&#{Issues.getLabelsQueryString()}"
initialUrl = gl.utils.removeParamQueryString($(this).attr('href'), 'label_name[]')
if gl.utils.getParamQueryString('label_name[]')
newUrl = "#{gl.utils.mergeUrlParams(newParams, initialUrl)}&#{gl.utils.getParamQueryString('label_name[]')}"
else
newUrl = gl.utils.mergeUrlParams(newParams, initialUrl)
$(this).attr 'href', newUrl
......
......@@ -28,4 +28,20 @@
newUrl = "#{newUrl}#{(if newUrl.indexOf('?') > 0 then '&' else '?')}#{paramName}=#{paramValue}"
newUrl
# get parameter query string from url.
w.gl.utils.getParamQueryString = (param) ->
pageURL = decodeURIComponent(window.location.search.substring(1))
urlVariables = pageURL.split('&')
(
variables for variables in urlVariables when variables.indexOf(param) > -1
).join('&')
# removes parameter query string from url. returns the modified url
w.gl.utils.removeParamQueryString = (url, param) ->
url = decodeURIComponent(url)
urlVariables = url.split('&')
(
variables for variables in urlVariables when variables.indexOf(param) is -1
).join('&')
) window
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment