Commits

Chun-Ping Chang committed 454f64d

Fix regen API key error when use Firefox

Comments (0)

Files changed (2)

assets/js/custom/manage.js

 $(document).ready( function () {
-  var g_actMode = '',
-      g_objID = '',
-      g_hashUserID = '',
+  var g_actMode = undefined,
+      g_objID = undefined,
+      g_hashUserID = undefined,
       g_targetObj = {},
       g_apiKey = [],
-      g_apiDatas = '';
+      g_apiDatas = undefined;
 
-  var idxOldApiKey = '',
-      oldObjID = '',
-      spnApiKey = '',
-      newApiData = '';
+  var idxOldApiKey = undefined,
+      oldObjID = undefined,
+      spnApiKey = undefined,
+      newApiData = undefined;
+
+  var callCount = 0;
 
   // Add Project Dialog
   $("#modalAddMod").bind("show", function() {
     }
 
     $("#btnSave").click( function () {
-      console.log("SAVE");
-
       var projInfo = {};
       projInfo.name = $('#txtProjName').val();
       projInfo.link = $('#txtWebLink').val();
             case 'MODIFY':
               init();
           }
-        },
-        error: function (res) {
-          console.log(res);
         }
       });
 
     });
 
     $("#btnCancel").click( function () {
-      console.log("CANCEL");
       $("#modalAddMod").modal('hide');
     });
   });
   // Delete Project Confirm Dialog
   $("#modalDelAlert").bind("show", function() {
     $("#delYes").click( function () {
-      console.log("YES");
       $.ajax({
         type:   'GET',
         url:    '/delete/apikey/' + g_objID,
         dataType: 'json',
         cache:  false,
         success: function (res) {
-          console.log(res);
           g_targetObj.fadeOut();
-
-        },
-        error: function (res) {
-          console.log(res);
         }
       });
       $("#modalDelAlert").modal('hide');
     });
 
     $("#delNo").click( function () {
-      console.log("NO");
       $("#modalDelAlert").modal('hide');
     });
   });
   // Regen API key Confirm Dialog
   $("#modalRegenAlert").bind("show", function() {
     $("#regenYes").click( function () {
-      console.log("YES");
-
       $.ajax({
         type:   'GET',
         url:    '/regen/apikey/' + g_objID,
         dataType: 'json',
         success: function (res) {
-          console.log(res[0]);
-          g_apiKey[idxOldApiKey] = res[0];
-          g_apiDatas[res[0]] = newApiData;
-          delete g_apiDatas[oldObjID];
-          g_targetObj.attr('id', g_apiKey[idxOldApiKey]);
-          g_objID = g_targetObj.attr('id');
-          spnApiKey.text(res[0]);
+          if (callCount === 0) {
+            g_apiKey[idxOldApiKey] = res[0];
+            g_apiDatas[res[0]] = newApiData;
+            delete g_apiDatas[oldObjID];
+            g_targetObj.attr('id', g_apiKey[idxOldApiKey]);
+            g_objID = g_targetObj.attr('id');
+            spnApiKey.text(res[0]);
+            callCount += 1;
+          }
         },
         error: function (res) {
-          console.log(res);
           spnApiKey.text('Can not re-generate API key.');
         }
       });
 
+      callCount = 0;
       $("#modalRegenAlert").modal('hide');
     });
 
     $("#regenNo").click( function () {
-      console.log("NO");
       $("#modalRegenAlert").modal('hide');
     });
   });
   // bind event to func button
   $('.add').on('click', function (e) {
     e.preventDefault();
-    console.log('add api key');
     $('#modalAct').text('Add');
     g_actMode = 'ADD';
     $('#frmAddModify').find(':input').each(function() {
 
   $('div.div_table').on('click', 'a.del', function (e) {
     e.preventDefault();
-    console.log('delete project');
     g_objID = $(this).parent().parent().parent().attr('id');
     g_targetObj = $(this).parent().parent().parent();
     $('#spnProjName').text(g_apiDatas[g_objID].name);
 
   $('div.div_table').on('click', 'a.modify', function (e) {
     e.preventDefault();
-    console.log('modify project');
     $('#modalAct').text('Modify');
     g_actMode = 'MODIFY';
     g_objID = $(this).parent().parent().parent().attr('id');
 
   $('div.div_table').on('click', 'a.regen', function (e) {
     e.preventDefault();
-    console.log('regen api key');
 
     idxOldApiKey = $.inArray(g_objID, g_apiKey);
     g_objID = $(this).parent().parent().parent().attr('id');
             <!-- The drop down menu -->
             <ul class="nav pull-right">
               <li><a href="/logout">Log Out</a></li>
-              <!--<li class="divider-vertical"></li>-->
-              <!--<li class="drop down">-->
-              <!--<a class="dropdown-toggle" href="#" data-toggle="dropdown">Log In <strong class="caret"></strong></a>-->
-              <!--<div class="dropdown-menu" style="padding: 15px; padding-bottom: 0px;">-->
-                <!--<form id="frmLogin">-->
-                  <!--<input id="txtUserID" style="margin-bottom: 15px;" type="text" name="txtUserID" size="30" />-->
-                  <!--<input id="txtUserPW" style="margin-bottom: 15px;" type="password" name="txtUserPW" size="30" />-->
-
-                  <!--<input class="btn btn-primary" style="clear: left; width: 100%; height: 32px; font-size: 13px;" type="button" id="btnLogin" name="btnLogin" value="Log In" />-->
-                <!--</form>-->
-              <!--</div>-->
-              <!--</li>-->
             </ul>
           </div>
           <!--/.nav-collapse -->
         <div id="mgtContent" class="span8 offset2">
           <div> <h3>Hello <span class="spnUserID">USER</span>! Here’s a list of your API Keys:</h3> </div>
 
-          <!--<div class="span2 offset6">-->
-            <!--[><a class="btn btn-primary btn-mini refresh" href="#"><]-->
-              <!--[><i class="icon-refresh icon-white"></i><]-->
-              <!--[>Refresh<]-->
-            <!--[></a><]-->
-            <!--<a class="btn btn-primary btn-mini add" href="#">-->
-              <!--<i class="icon-plus icon-white"></i>-->
-              <!--Add-->
-            <!--</a>-->
-          <!--</div>-->
-
           <div class="div_table">
           </div>
 
           <hr>
 
           <div>
-            <!--<a class="btn btn-primary btn-mini refresh" href="#">-->
-              <!--<i class="icon-refresh icon-white"></i>-->
-              <!--Refresh-->
-            <!--</a>-->
             <a class="btn btn-primary btn-small add" href="#">
               <i class="icon-plus icon-white"></i>
               Add
         <h3>ReGenerate API key</h3>
       </div>
       <div class="modal-body">
-        <p>Re-generate API key will clean all layer and node that created by this API key</p>
-        <p>Do you REALLY want to do this modify?</p>
+        <p>Re-generate API key will clean all layers and nodes that created under this API key</p>
+        <p>CONTINUE?</p>
       </div>
       <div class="modal-footer">
         <a href="#" class="btn btn-primary" id="regenYes">Yes</a>