public
Description: Git mirror of the CMS Made Simple 2.0 rewrite
Homepage: http://cmsmadesimple.org
Clone URL: git://github.com/tedkulp/cmsmadesimple-2-0.git
Search Repo:
Removed xajax from addcontent.php
Added methods to CmsAjax to handle serialized forms as function params
Added modify_attribute method to the response handler
Added onclick handler to the admin buttons template

Signed-off-by: Ted Kulp <ted@cmsmadesimple.org>


git-svn-id: http://svn.cmsmadesimple.org/svn/cmsmadesimple/trunk@4322 
3d254a34-79dc-0310-9e5f-be208747d8a0
tedkulp (author)
Thu Jan 31 20:45:54 -0800 2008
commit  cb5ab2d112f09296359b3e69ad9ebdd7df80e9fa
tree    730a772af9e259e98b965a2520cf49d1e0c395eb
parent  f7c9da6d71311ad8921d9969b42a18aa006cea90
...
51
52
53
54
55
56
57
 
58
59
 
 
 
 
60
61
62
63
64
65
 
66
67
68
...
167
168
169
170
171
 
 
 
172
173
174
...
176
177
178
179
 
180
181
 
182
183
184
...
196
197
198
199
200
201
202
 
203
204
205
206
207
208
 
 
209
210
 
211
212
213
...
291
292
293
294
295
296
297
298
299
300
 
 
 
 
 
 
 
 
301
302
303
...
51
52
53
 
 
 
 
54
55
 
56
57
58
59
60
61
62
63
64
 
65
66
67
68
...
167
168
169
 
 
170
171
172
173
174
175
...
177
178
179
 
180
181
 
182
183
184
185
...
197
198
199
 
 
 
 
200
201
 
 
 
 
 
202
203
204
 
205
206
207
208
...
286
287
288
 
 
 
 
 
 
 
289
290
291
292
293
294
295
296
297
298
299
0
@@ -51,18 +51,18 @@ $preview = array_key_exists('previewbutton', $_POST);
0
 $submit = array_key_exists('submitbutton', $_POST);
0
 $apply = array_key_exists('applybutton', $_POST);
0
 
0
-require_once(dirname(dirname(__FILE__)) . '/lib/xajax/xajax.inc.php');
0
-$xajax = new xajax();
0
-$xajax->registerFunction('ajaxpreview');
0
-$xajax->registerFunction('change_block_type');
0
+$cms_ajax = new CmsAjax();
0
 
0
-$xajax->processRequests();
0
+$cms_ajax->register_function('ajaxpreview');
0
+$cms_ajax->register_function('change_block_type');
0
+
0
+$cms_ajax->process_requests();
0
 
0
 #See what kind of permissions we have
0
 $access = (check_permission($userid, 'Add Pages') || check_permission($userid, 'Modify Page Structure'));
0
 
0
 require_once("header.php");
0
-CmsAdminTheme::inject_header_text($xajax->getJavascript('../lib/xajax')."\n");
0
+CmsAdminTheme::inject_header_text($cms_ajax->get_javascript()."\n");
0
 
0
 #No access? Just display an error and exit.
0
 if (!$access) {
0
@@ -167,8 +167,9 @@ function change_block_type($params, $block_id, $new_block_type)
0
   $div_id = 'content-form-' . $block_id;
0
   $page_object->$type_param = $new_block_type;
0
   
0
-  $objResponse = new xajaxResponse();
0
-  $objResponse->addAssign("serialized_content", "value", serialize_object($page_object));
0
+  $resp = new CmsAjaxResponse();
0
+
0
+  $resp->modify_attribute("#serialized_content", "value", serialize_object($page_object));
0
   
0
   $smarty->_compile_source('metadata template', $page_object->create_block_type($block_id), $_compiled);
0
   @ob_start();
0
@@ -176,9 +177,9 @@ function change_block_type($params, $block_id, $new_block_type)
0
   $result = @ob_get_contents();
0
   @ob_end_clean();
0
   
0
-  $objResponse->addAssign($div_id, 'innerHTML', $result);
0
+  $resp->modify_html("#$div_id", $result);
0
   
0
-  return $objResponse->getXML();
0
+  return $resp->get_result();
0
 }
0
 
0
 function ajaxpreview($params)
0
@@ -196,18 +197,12 @@ function ajaxpreview($params)
0
   $tmpfname = create_preview($page_object);
0
   $url = $config["root_url"] . '/index.php?tmpfile=' . urlencode(basename($tmpfname));
0
   
0
-  $objResponse = new xajaxResponse();
0
-  $objResponse->addAssign("previewframe", "src", $url);
0
-  $objResponse->addAssign("serialized_content", "value", serialize_object($page_object));
0
-  $count = 0;
0
+  $resp = new CmsAjaxResponse();
0
 
0
-  foreach (array("content", "advanced") as $tabname)
0
-  {
0
-    $objResponse->addScript("Element.removeClassName('".$tabname."', 'active');Element.removeClassName('".$tabname."_c', 'active');$('".$tabname."_c').style.display = 'none';");
0
-  }
0
-  $objResponse->addScript("Element.addClassName('preview', 'active');Element.addClassName('preview_c', 'active');$('preview_c').style.display = '';");
0
+  $resp->modify_attribute("#previewframe", "src", $url);
0
+  $resp->modify_attribute("#serialized_content", "value", serialize_object($page_object));
0
 
0
-  return $objResponse->getXML();
0
+  return $resp->get_result();
0
 }
0
 
0
 //Get a working page object
0
@@ -291,13 +286,14 @@ $smarty->assign('metadata_box', create_textarea(false, $page_object->metadata, '
0
 
0
 //extra buttons
0
 $ExtraButtons = array(
0
-     array(
0
-       'name' => 'preview',
0
-       'class' => 'positive preview',
0
-       'image' => '',
0
-       'caption' => lang('preview'),
0
-       ),
0
-     );
0
+  array(
0
+    'name' => 'preview',
0
+    'class' => 'positive preview',
0
+    'image' => '',
0
+    'caption' => lang('preview'),
0
+    'onclick' => "$('#page_tabs').tabsClick(4);return false;"
0
+  ),
0
+);
0
 
0
 $smarty->assign('DisplayButtons', $ExtraButtons);
0
 
...
17
18
19
20
 
21
22
23
...
17
18
19
 
20
21
22
23
0
@@ -17,7 +17,7 @@
0
       <li><a href="#advanced"><span>Advanced</span></a></li>
0
       <li><a href="#permissions"><span>Permissions</span></a></li>
0
       {if $can_preview eq true}
0
-       <li><a href="#preview"{if $showpreview eq true} class="active"{/if} onclick="xajax_ajaxpreview(xajax.getFormValues('contentform'));return false;"><span>Preview</span></a></li>
0
+       <li><a href="#preview"{if $showpreview eq true} class="active"{/if} onclick="cms_ajax_ajaxpreview($('#contentform').serializeForCmsAjax());return false;"><span>Preview</span></a></li>
0
       {/if}
0
     </ul>
0
     <div id="content">
...
5
6
7
8
 
9
10
11
12
...
5
6
7
 
8
9
10
11
12
0
@@ -5,7 +5,7 @@
0
 
0
   {* loop through to get custom buttons *}
0
   {foreach from=$DisplayButtons item=OneButton}
0
-    <input type="submit" value="{$OneButton.caption}" name="{$OneButton.name}" class="{$OneButton.class}" />
0
+    <input type="submit" value="{$OneButton.caption}" name="{$OneButton.name}" class="{$OneButton.class}" {if isset($OneButton.class)} onclick="{$OneButton.onclick}" {/if} />
0
   {/foreach}
0
 
0
 </div>
0
\ No newline at end of file
...
43
44
45
46
 
47
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
50
51
...
43
44
45
 
46
47
 
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
0
@@ -43,9 +43,22 @@ class CmsAjax extends CmsObject
0
       $args = array();
0
       if ($xml)
0
       {
0
-        foreach($xml->e as $element)
0
+        foreach ($xml->xpath('/ajaxarray/*') as $element)
0
         {
0
-          $args[] = (string)$element;
0
+          switch($element->getName())
0
+          {
0
+            case 'e':
0
+              $args[] = (string)$element;
0
+              break;
0
+            case 'sf':
0
+              $str = (string)$element;
0
+              $result = array();
0
+
0
+              parse_str($str, $result);
0
+              
0
+              $args[] = $result;
0
+              break;
0
+          }
0
         }
0
       }
0
       
...
29
30
31
32
 
 
 
 
 
 
33
34
35
...
29
30
31
 
32
33
34
35
36
37
38
39
40
0
@@ -29,7 +29,12 @@ class CmsAjaxResponse extends CmsObject
0
   
0
   function modify_html($selector, $text)
0
   {
0
-    $this->result .= '<as><s>' . $selector . '</s><t><![CDATA[' . $text . ']]></t></as>';
0
+    $this->result .= '<mh><s>' . $selector . '</s><t><![CDATA[' . $text . ']]></t></mh>';
0
+  }
0
+  
0
+  function modify_attribute($selector, $attribute, $text)
0
+  {
0
+    $this->result .= '<ma><s>' . $selector . '</s><a><![CDATA[' . $attribute . ']]></a><t><![CDATA[' . $text . ']]></t></ma>';
0
   }
0
   
0
   function script($text)
...
114
115
116
117
 
118
119
120
...
114
115
116
 
117
118
119
120
0
@@ -114,7 +114,7 @@ class Content extends CmsContentBase
0
         <div class="accordion_content">
0
           <div class="pageoverflow">
0
             <p class="pagetext">'.lang('blocktype').':</p>
0
-            <select name="content[property]['.$block['id'].'-block-type]" id="'.$block['id'].'-block-type" onchange="xajax_change_block_type(xajax.getFormValues(\'contentform\'), \''.$block['id'].'\', \'\' + $(\'#'.$block['id'].'-block-type\').val()); return false;">
0
+            <select name="content[property]['.$block['id'].'-block-type]" id="'.$block['id'].'-block-type" onchange="cms_ajax_change_block_type($(\'#contentform\').serializeForCmsAjax(), \''.$block['id'].'\', \'\' + $(\'#'.$block['id'].'-block-type\').val()); return false;">
0
               '.$this->create_block_type_options($type).'
0
             </select>
0
           </div>
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
...
34
35
36
 
37
38
39
...
45
46
47
48
 
49
50
51
52
53
54
 
 
 
 
 
 
 
 
55
56
57
...
67
68
69
70
 
 
 
 
 
71
72
73
74
75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
...
7
8
9
10
11
12
13
...
19
20
21
 
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
...
49
50
51
 
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
0
@@ -1,30 +1,3 @@
0
-jQuery.fn.highlight = function(color, speed, easing, callback) {
0
-
0
-  /* current color of the element */
0
-  var originalColor = jQuery(this).css('backgroundColor');
0
-  
0
-  /* find the first "real" color from the parent elements */
0
-  var parentEl = this.parentNode;
0
-  while(originalColor == 'transparent' && parentEl) {
0
-    originalColor = jQuery(parentEl).css('backgroundColor');
0
-    parentEl = parentEl.parentNode;
0
-  }
0
-  
0
-  /* swap element to the highlight color */
0
-  jQuery(this).css('backgroundColor', color);
0
-  
0
-  /* in IE, style is an object */
0
-  if(typeof this.oldStyleAttr == 'object') {
0
-   this.oldStyleAttr = this.oldStyleAttr["cssText"];
0
-  }
0
-  
0
-  /* animate back to the original color */
0
-  jQuery(this).animate(
0
-    {'backgroundColor':originalColor},
0
-    speed
0
-  );
0
-};
0
-
0
 function cms_ajax_call(fName, aArgs, iInt)
0
 {
0
   $.ajax({
0
@@ -34,6 +7,7 @@ function cms_ajax_call(fName, aArgs, iInt)
0
         cms_ajax_args: cms_ajax_array_to_xml(jQuery.makeArray(aArgs))
0
       },
0
       dataType: "xml",
0
+      type: "POST",
0
       success: function (xml) {
0
         cms_ajax_callback(xml);
0
       }
0
@@ -45,13 +19,21 @@ function cms_ajax_callback(xml)
0
   $(xml).find('ajax').children().each(
0
     function()
0
     {
0
-      if (this.tagName == 'as') //from ->modify_html
0
+      if (this.tagName == 'mh') //from ->modify_html
0
       {
0
         var selector = $(this).find("s").text();
0
         var val = $(this).find("t").text();
0
         
0
         $(selector).html(val);
0
       }
0
+      else if (this.tagName == 'ma') //from ->modify_attribute
0
+      {
0
+        var selector = $(this).find("s").text();
0
+        var attribute = $(this).find("a").text();
0
+        var val = $(this).find("t").text();
0
+        
0
+        $(selector).attr(attribute, val);
0
+      }
0
       else if (this.tagName == 'sc') //from ->script
0
       {
0
         var val = $(this).find("t").text();
0
@@ -67,9 +49,46 @@ function cms_ajax_array_to_xml(ary)
0
   var xml = "<ajaxarray>";
0
   for (i = 0; i < ary.length; i++)
0
   {
0
-    xml += '<e><![CDATA[' + ary[i] + ']]></e>';
0
+    var elem = String(ary[i]);
0
+    if (elem.indexOf("<sf>") == 0) //handle a serialized form
0
+      xml += elem;
0
+    else
0
+      xml += '<e><![CDATA[' + ary[i] + ']]></e>';
0
   }
0
   xml += "</ajaxarray>";
0
 
0
   return xml;
0
 }
0
+
0
+jQuery.fn.serializeForCmsAjax = function() {
0
+
0
+ return '<sf><![CDATA[' + this.serialize() + ']]></sf>';
0
+
0
+};
0
+
0
+jQuery.fn.highlight = function(color, speed, easing, callback) {
0
+
0
+  /* current color of the element */
0
+  var originalColor = jQuery(this).css('backgroundColor');
0
+  
0
+  /* find the first "real" color from the parent elements */
0
+  var parentEl = this.parentNode;
0
+  while(originalColor == 'transparent' && parentEl) {
0
+    originalColor = jQuery(parentEl).css('backgroundColor');
0
+    parentEl = parentEl.parentNode;
0
+  }
0
+  
0
+  /* swap element to the highlight color */
0
+  jQuery(this).css('backgroundColor', color);
0
+  
0
+  /* in IE, style is an object */
0
+  if(typeof this.oldStyleAttr == 'object') {
0
+   this.oldStyleAttr = this.oldStyleAttr["cssText"];
0
+  }
0
+  
0
+  /* animate back to the original color */
0
+  jQuery(this).animate(
0
+    {'backgroundColor':originalColor},
0
+    speed
0
+  );
0
+};

Comments

    No one has commented yet.