Просмотр исходного кода

JSON parser improved. Fixed problem with parsing special symbols

Dima Malishev 14 лет назад
Родитель
Сommit
b472a367d5
6 измененных файлов с 107 добавлено и 11 удалено
  1. 1 0
      web/js/_settings.js
  2. 1 0
      web/js/actions.js
  3. 5 3
      web/js/app.js
  4. 7 4
      web/js/helpers.js
  5. 32 0
      web/js/html.js
  6. 61 4
      web/js/templates.js

+ 1 - 0
web/js/_settings.js

@@ -15,6 +15,7 @@ App.Constants.DNS_FORM_ID         = 'dns-form';
 App.Constants.USER_FORM_ID        = 'user-form';
 App.Constants.WEB_DOMAIN_FORM_ID  = 'web_domain-form';
 App.Constants.DB_FORM_ID          = 'db-form';
+App.Constants.CRON_FORM_ID        = 'cron-form';
 
 App.Settings.ajax_url = 1;
 App.Settings.uri = location.href.replace('index.html', '');

+ 1 - 0
web/js/actions.js

@@ -135,6 +135,7 @@ App.Actions.cancel_form = function(evt, params) {
         $('#' + form_id).remove();
     }
     else {
+        fb.warn(elm.find('.source').val());
         var options = App.Helpers.evalJSON(elm.find('.source').val());
         var entry_name = App.Env.world.toLowerCase() + '_entry';
         var tpl = App.HTML.Build[entry_name](options);

+ 5 - 3
web/js/app.js

@@ -189,13 +189,15 @@ App.Ajax.request = function(jedi_method, data, callback)
         type: data.request_method || "POST",
         data: $.extend(data, {'jedi_method': jedi_method}),
         dataType: "text",
-        async:true,
+        async: true,
         success: function(reply)
         {                
-            timer.start();        
+            reply = reply.replace(/\\'/gi, '');
+            reply = reply.replace(/\'/gi, '');
+            //timer.start();        
             callback && callback(jsonParse(reply));
             App.Helpers.afterAjax();
-            timer.stop(jedi_method);            
+            //timer.stop(jedi_method);            
         },
         error: function() 
         {

+ 7 - 4
web/js/helpers.js

@@ -123,14 +123,17 @@ App.Helpers.getFirstValue = function(obj)
     return first;
 }
 
-App.Helpers.evalJSON = function(string) 
+App.Helpers.evalJSON = function(str) 
 {
-    return $.parseJSON(string);
+    /*str = str.replace(/\\'/gi, '');
+    str = str.replace(/\'/gi, '');
+    fb.warn(str);*/
+    return $.parseJSON(str);
 }
 
 App.Helpers.toJSON = function(object) 
-{
-    return ($.toJSON(object).replace(/'/gi, ''));
+{    
+    return ($.toJSON(object).replace(/\\'/gi, ''));
 }
 
 

+ 32 - 0
web/js/html.js

@@ -357,6 +357,38 @@ App.HTML.Build.cron_entry = function(o, key)
     
     return tpl.finalize();
 }
+     
+
+App.HTML.Build.cron_form = function(options, id) 
+{try{
+    if('undefined' == typeof App.Env.initialParams) {
+        return alert('PLease wait a bit. Some background processes are not yet executed. Thank you for patience.');
+    }
+    var tpl = App.Templates.get('FORM', 'cron');
+    tpl.set(':source', options);
+
+    options = App.Helpers.evalJSON(options) || {};
+    if (App.Helpers.isEmpty(options)) {
+       tpl.set(':title', 'New cron entry'); 
+       tpl.set(':save_button', 'ADD'); 
+    }
+    else {
+        tpl.set(':title', 'Edit cron entry'); 
+        tpl.set(':save_button', 'SAVE'); 
+    }
+    
+    options = !App.Helpers.isEmpty(options) ? options : {DAY:'', MONTH: '', WDAY:'',HOUR:'',CMD:'',MIN:''};    
+    tpl = App.HTML.setTplKeys(tpl, options);  
+
+    /*tpl.set(':id', id || ''); 
+    tpl.set(':IP_ADDRESS', options.IP_ADDRESS || '');
+    tpl.set(':NETMASK', options.NETMASK || '');
+    tpl.set(':NAME', options.NAME || '');*/
+    
+    //tpl = App.HTML.Build.ip_selects(tpl, options);
+}catch(e){fb.error(e);}
+    return tpl.finalize();
+}
     
 
 App.HTML.Build.dns_records = function(records)

+ 61 - 4
web/js/templates.js

@@ -44,7 +44,7 @@ App.Templates.html = {
     dns: {
         FORM: [
             '<div style="margin-top: 25px;" class="b-new-entry b-new-entry_dns" id="~!:id~!">\
-                <input type="hidden" name="source" class="source" value=\'~!:source~!\'>\
+                <input type="hidden" name="source" class="source" value=~!:source~!>\
                     <input type="hidden" name="target" class="target" value=\'\'>\
                     <div class="entry-header">~!:title~!</div>\
                     <div class="errors">\
@@ -86,8 +86,8 @@ App.Templates.html = {
         ],        
         ENTRIES_WRAPPER: ['<div class="dns-list items-list">~!:content~!</div>'],
         ENTRY: ['<div class="row dns-details-row ~!:CHECKED~!">\
-                            <input type="hidden" name="source" class="source" value=\'~!:source~!\'>\
-                            <input type="hidden" class="target" name="target" value="" />\
+                            <input type="hidden" name="source" class="source" value=~!:source~! />\
+                            <input type="hidden" class="target" name="target" value=\'\' />\
                             <div class="row-actions-box cc">\
                                         <div class="check-this check-control"></div>\
                                         <div class="row-operations">\
@@ -763,9 +763,66 @@ App.Templates.html = {
 					</div>']
     },
     cron: {
+        FORM: ['<div class="b-new-entry b-new-entry_cron">\
+						<input type="hidden" name="source" class="source" value=\'~!:source~!\'>\
+                        <input type="hidden" name="target" class="target" value=\'\'>\
+                        <div class="entry-header">~!:title~!</div>\
+						<div class="form-error">\
+							<div class="error-box">\
+							</div>\
+						</div>\
+						<div class="form-row form-row-line run-at-box cc">\
+							<span class="row-header">run at:</span>\
+							<div class="field-box cron-minute-box">\
+								<label for="#" class="field-label">minute:<br>(0&mdash;59)</label>\
+								<div class="field-box-inner cc">\
+									<input type="text" value="~!:MIN~!" name="MIN" class="text-field">\
+								</div>\
+							</div>\
+							<div class="field-box cron-hour-box">\
+								<label for="#" class="field-label">hour:<br>(0&mdash;23)</label>\
+								<div class="field-box-inner cc">\
+									<input type="text" value="~!:HOUR~!" name="HOUR" class="text-field">\
+								</div>\
+							</div>\
+							<div class="field-box cron-day-box">\
+								<label for="#" class="field-label">day of Month:<br>(1&mdash;31)</label>\
+								<div class="field-box-inner cc">\
+									<input type="text" value="~!:DAY~!" name="DAY" class="text-field">\
+								</div>\
+							</div>\
+							<div class="field-box cron-month-box">\
+								<label for="#" class="field-label">Month:<br>(1&mdash;12)(Jan&mdash;Dec)</label>\
+								<div class="field-box-inner cc">\
+									<input type="text" value="~!:MONTH~!" name="MONTH" class="text-field">\
+								</div>\
+							</div>\
+							<div class="field-box cron-week-box">\
+								<label for="#" class="field-label">day of Week:<br>(1&mdash;7)(Sun&mdash;Sat)</label>\
+								<div class="field-box-inner cc">\
+									<input type="text" value="~!:WDAY~!" name="WDAY" class="text-field">\
+								</div>\
+							</div>\
+						</div>\
+						<div class="form-row cc">\
+							<label for="#" class="field-label">command:</label>\
+							<textarea class="textarea" name="CMD">~!:CMD~!</textarea>\
+						</div>\
+						<div class="form-row cc">\
+							<label for="#" class="field-label">report to: <span class="remark">(devide by comma ",")</span></label>\
+							<textarea class="textarea"></textarea>\
+						</div>\
+						<div class="form-row buttons-row cc">\
+							<input type="submit" value="~!:save_button~!" class="add-entry-btn">\
+							<span class="cancel-btn do_action_cancel_form">Cancel</span>\
+							<a target="_blank" href="http://vestacp.com/docs/cron/" class="help-btn">Help</a>\
+						</div>\
+					</div>'],
         ENTRIES_WRAPPER: ['<div class="db-list">~!:content~!</div>'],
         ENTRY: ['<div class="row first-row cron-details-row">\
-						<div class="row-actions-box cc">\
+						<input type="hidden" name="source" class="source" value=\'~!:source~!\'>\
+                        <input type="hidden" name="target" class="target" value=\'\'>\
+                        <div class="row-actions-box cc">\
 							<div class="check-this check-control"></div>\
 							<div class="row-operations">\
 								~!:SUSPENDED_TPL~!\