Commit 3d435707 authored by Romain Loth's avatar Romain Loth

profile: js select correct option in menus

parent 1b0fc6f9
......@@ -13,6 +13,21 @@
* NB The uinfo variable should be set to template's user.json_info value.
*/
// first menu setup from DB values
function selectSavedMenus(uinfo) {
for (var i in cmxClt.COLS) {
var colType = cmxClt.COLS[i][3]
// m <=> menu
if (colType == 'm') {
var colName = cmxClt.COLS[i][0]
var chosenV = uinfo[colName]
var selectElt = document.getElementById(colName)
selectElt.selectedIndex = selectElt.querySelector(`option[value="${chosenV}"]`).index
}
}
}
selectSavedMenus(uinfo)
// initialize form controllers
cmxClt.uform.initialize("comex_profile_form", completionAsYouGo)
......@@ -39,12 +54,17 @@ function completionAsYouGo() {
// list of missing fields
cmxClt.uform.mainMessage.innerHTML += cmxClt.ulListFromLabelsArray(mandatoryMissingFields, ['red']) + cmxClt.ulListFromLabelsArray(optionalMissingFields, ['white'], "You may also want to fill:")
}
// stamp => #last_modified_date
cmxClt.uform.stampTime()
console.log("timestamp", cmxClt.uform.timestamp.value)
}
// run first check on existing profile data pre-filled by the template
completionAsYouGo()
// 2 exposed vars for inline js controls
var teamCityDivStyle = document.getElementById('team_city_div').style
var otherInstDivStyle = document.getElementById('other_org_div').style
console.log("profile controllers load OK")
......@@ -42,14 +42,10 @@ function testAsYouGo() {
else {
cmxClt.uform.submitButton.disabled = true
}
var now = new Date()
regTimestamp.value = now.toISOString()
// stamp => #last_modified_date
cmxClt.uform.stampTime()
}
var regTimestamp = document.getElementById('last_modified_date')
var subPage1Style = document.getElementById('subpage_1').style
var subPage2Style = document.getElementById('subpage_2').style
......
......@@ -110,8 +110,10 @@ var cmxClt = (function() {
ccModule.uform.initialize
ccModule.uform.testFillField
ccModule.uform.stampTime
ccModule.uform.mainMessage = document.getElementById('main_message')
ccModule.uform.submitButton = document.getElementById('form_submit')
ccModule.uform.timestamp = document.getElementById('last_modified_date')
// dates up to 2049/12/31
ccModule.uform.validDate = new RegExp( /^20[0-4][0-9]\/(?:0?[1-9]|1[0-2])\/(?:0?[1-9]|[1-2][0-9]|3[0-1])$/)
......@@ -159,11 +161,31 @@ var cmxClt = (function() {
var fieldGroup = ccModule.COLS[i][2]
var fieldType = ccModule.COLS[i][3]
var actualValue = wholeFormData.get(fieldName)
// python residue ~~~> can correct on the fly
// --------------
// POSS better strategy ?
if (params.fixResidue) {
// "None" as a string
if (actualValue == "None") {
actualValue = null
document.getElementById(fieldName).value = ""
}
// arrays of text
if (fieldType == "at" && actualValue
&& actualValue.charAt(0) == '['
&& actualValue.charAt(1) == "'") {
actualValue = actualValue.replace(/[\[\]']/g,'')
document.getElementById(fieldName).value = actualValue
}
}
// filled/not filled validation
// ----------------------------
// skip non-plsfill elements
if (fieldGroup != 'plsfill') continue ;
var actualValue = wholeFormData.get(fieldName)
// get a human-readable label
var labelElt = document.querySelector('label[for='+fieldName+']')
var fieldLabel = labelElt ? labelElt.innerText : fieldName
......@@ -173,23 +195,6 @@ var cmxClt = (function() {
actualValue = null
}
// python residue ~~~> can correct on the fly
// POSS better strategy ?
if (params.fixResidue) {
// "None" as a string
if (actualValue == "None") {
actualValue = null
document.getElementById(fieldName).value = ""
}
// arrays of text
if (fieldType == "at" && actualValue
&& actualValue.charAt(0) == '['
&& actualValue.charAt(1) == "'") {
actualValue = actualValue.replace(/[\[\]']/g,'')
document.getElementById(fieldName).value = actualValue
}
}
// debug
// console.log(
// "cmxClt.testFillField: field", fieldName,
......@@ -226,6 +231,12 @@ var cmxClt = (function() {
otherMissingFields ]
}
// simple timestamp on #last_modified_date element
// ------------------
ccModule.uform.stampTime = function () {
var now = new Date()
ccModule.uform.timestamp.value = now.toISOString()
}
// ===================================================================
// additional controllers for detailed forms like /register, /profile
......
......@@ -377,14 +377,14 @@
<!-- ======================================================================= -->
{% block last_imports %}
<!-- our js -->
<script src="{{ url_for('static', filename='js/comex_user_shared.js') }}"></script>
<script src="{{ url_for('static', filename='js/comex_page_profile_controllers.js') }}"></script>
<script type="text/javascript">
// ---------
// a copy of the user info in json
// ---------
var uinfo = {{current_user.json_info|safe}};
</script>
<!-- our js -->
<script src="{{ url_for('static', filename='js/comex_user_shared.js') }}"></script>
<script src="{{ url_for('static', filename='js/comex_page_profile_controllers.js') }}"></script>
{% endblock %}
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