Advertising sustains the DA. Ads are hidden for members. Join today

DrupalGap and CCK

Last updated on
30 April 2025

drupalGap and cck

In this section we will explain how to:

show cck field:

  1. create your own content type and add custom field to it (e.g. new_field)
  2. in drupalgap/pages/node.js edit drupalgap_page_node_success function:
// Node body.
var body;
if (drupalgap_site_settings.variable.drupal_core == "6") {
	body = drupalgap_page_node.body;
}
else if (drupalgap_site_settings.variable.drupal_core == "7") {
	body = drupalgap_page_node.body.und[0].safe_value;
}

//$('#drupalgap_page_node .content').html(body);
//sh:
//Node field_new_field 
//Add cck field after body
//you must replace new_field with your field and style it as you want 
if(drupalgap_page_node.field_new_field)
	if(drupalgap_page_node.field_new_field.und)
		$('#drupalgap_page_node .content').html(body + "<br/>new field is: " + drupalgap_page_node.field_new_field.und[0].value);
	else
		$('#drupalgap_page_node .content').html(body);
else
	$('#drupalgap_page_node .content').html(body);

save cck field:

1.edit drupalgap/pages/node_edit.html:

<div>
  <label for="drupalgap_page_node_edit_body">Body</label>
  <textarea id="drupalgap_page_node_edit_body" rows="5"></textarea>
</div>
<!-- sh:for take cck value from user -->
<div id="drupalgap_page_node_edit_new_field_box">
  <label for="drupalgap_page_node_edit_new_field">new_field</label>
  <input type="text" id="drupalgap_page_node_edit_new_field" />
</div>
<!-- /cck field -->

2. edit drupalgap/pages/node_edit.js:

$('#drupalgap_page_node_edit_title').val("");
$('#drupalgap_page_node_edit_body').val("");
//sh:add this line for cck field
$('#drupalgap_page_node_edit_new_field').val("");
var body;
if (drupalgap_site_settings.variable.drupal_core == "6") {
body = node.body;
}
else if (drupalgap_site_settings.variable.drupal_core == "7") {
body = node.body.und[0].safe_value;
}
$('#drupalgap_page_node_edit_body').val(body);
//sh:add these lines to fill cck field
if(node.field_new_field){
if(node.field_new_field.und)
	$('#drupalgap_page_node_edit_new_field').val(node.field_new_field.und[0].value);						
}
else
$('#drupalgap_page_node_edit_new_field_box').hide();
$('#drupalgap_page_node_edit_submit').live('click',function(){
try {

// Grab input and validate.
var title = $('#drupalgap_page_node_edit_title').val();
if (!title) { alert('Please enter a title.'); return false; }
var body = $('#drupalgap_page_node_edit_body').val();
if (!body) { alert('Please enter some body content.'); return false; }
//sh: add these lines for take cck field
var new_field = $('#drupalgap_page_node_edit_new_field').val();

if (!drupalgap_page_node_edit_nid) { // new nodes...
options = {
	"node":{
		"type":drupalgap_page_node_edit_type,
		"title":title,
		"body":body,
		"new_field":new_field,
	},
	"error":function(jqXHR, textStatus, errorThrown) {
		alert("drupalgap_page_node_edit_submit - Failed to create " + drupalgap_page_node_edit_type + ", review the debug console log for more information.");
	},
	"success":function(node) {
		// Created node successfully, view the node.
		drupalgap_page_node_nid = node.nid;
		$.mobile.changePage("node.html");
	},
};
drupalgap_services_node_create.resource_call(options);
}
else { // existing nodes...
// Retrieve the node, update the values.
options = {
	"nid":drupalgap_page_node_edit_nid,
	"error":function(jqXHR, textStatus, errorThrown) {
		alert("drupalgap_page_node_edit_submit - failed to load node (" + drupalgap_page_node_edit_nid + ")");
	},
	"success":function(node) {
		// Node was retrieved, update its values.
		node.title = title;
		node.body = body;
		//sh: add this line for cck
		node.field_new_field=new_field;
		node_update_options = {
			"node":node,
			"error":function(jqXHR, textStatus, errorThrown) {
				alert(result.errorThrown);
			},
			"success":function(data) {
				// Node was updated properly.
				$.mobile.changePage("node.html");
			},
		};
		drupalgap_services_node_update.resource_call(node_update_options);
	},
};
drupalgap_services_node_retrieve.resource_call(options);
}
}

3. edit drupalgap/services/node.js drupalgap_services_node_create.resource_call function:

var body;
if (drupalgap_site_settings.variable.drupal_core == "6") {
	body = "node[body]=" + encodeURIComponent(node.body);
}
else if (drupalgap_site_settings.variable.drupal_core == "7") {
	body = "node[language]=und&node[body][und][0][value]=" + encodeURIComponent(node.body);
}
//sh: add these lines for cck field
var new_field;
new_field= "node[field_new_field][und][0][value]="+ node.new_field;

// Build service call data string.
data = "node[type]=" + encodeURIComponent(node.type);
//data += "&node[title]=" + encodeURIComponent(node.title) + "&" + body;
//sh:edit this line for add cck
data += "&node[title]=" + encodeURIComponent(node.title) + "&" + body + "&" + new_field;

3. edit drupalgap/services/node.js drupalgap_services_node_update.resource_call function:

var body;
if (drupalgap_site_settings.variable.drupal_core == "6") {
	body = "node[body]=" + encodeURIComponent(node.body);
}
else if (drupalgap_site_settings.variable.drupal_core == "7") {
	body = "node[language]=und&node[body][und][0][value]=" + encodeURIComponent(node.body);
}
//sh: add this line for cck 
new_field="node[field_new_field][und][0][value]=" + node.field_new_field;

// Build the data string and options for the service call.
data = "node[type]=" + node.type;
data += "&node[title]=" + encodeURIComponent(node.title);
//data += "&" + body;
//sh: edit this line for cck
data += "&" + body + "&" + new_field;			
	

Help improve this page

Page status: Not set

You can: