I want replace this function by:
formatEditing: function(inDatum, inRowIndex){
this.needFormatNode(inDatum, inRowIndex);
return '<input class="dojoxGridInput" type="text" value="' + inDatum.replace(/"/g, '"') + '">';
},
How i can do it?
dojox.grid.cells.Cell.prototype.formatEditing = function(){}
Related
i've got many "compiled" underscore template ( some months ago i save compiled templates to on file, and accidentally remove original templates folder... :( ) is it pissible to "decompile" this templates? one of example:
UV.templates["template-button-widget"] = function() {
return $.trim(function(obj) {
var __t, __p = "",
__j = Array.prototype.join,
print = function() {
__p += __j.call(arguments, "")
};
with(obj || {}) __p += '\n\n <div class="button" data-id="' + (null == (__t = data._id) ? "" : _.escape(__t)) + '">\n\n <div class="icon"></div>\n\n </div>\n\n';
return __p
}.apply(this, arguments))
},
If you read over the source of _.template, you'll find it's simple enough that you could reverse it with a few hours of work. Make sure to find the code for your version of underscore (clearly yours isn't the most recent as there are changes), old docs can be found in the changelog.
Here's the code required to reverse your example template:
var compiled = function() {
return $.trim(function(obj) {
var __t, __p = "",
__j = Array.prototype.join,
print = function() {
__p += __j.call(arguments, "")
};
with(obj || {}) __p += '\n\n <div class="button" data-id="' + (null == (__t = data._id) ? "" : _.escape(__t)) + '">\n\n <div class="icon"></div>\n\n </div>\n\n';
return __p
}.apply(this, arguments))
};
var source = compiled.toString();
// Strip start/end code
source = source.substring(source.indexOf("with(obj || {}) __p += '\\n\\n") + 28);
source = source.substring(0, source.indexOf("\\n\\n';"));
// Reverse escape
source = source.replace(/' \+ \(null == \(__t = ([^)]+)\) \? "" : _.escape\(__t\)\) \+ '/g, "<%- $1 %>");
$('#result').text(source.replace(/\\n/g, "\n"));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.3.3/backbone-min.js"></script>
<pre id="result"/>
You can manually decompile it.. base on your code your template definition will be:
`<div class="button" data-id="<%= data._id %>'">
<div class="icon"></div>
</div>`
It is easy but for complex template it will be harder.
I have problem with old prestashop.
Wants to do to the name of the product is in the form of a list
attribute
br
attribute
br
...
<td><a href="index.php?tab=AdminCatalog&id_product='.$product['product_id'].'&updateproduct&token='.$tokenCatalog.'">
<span class="productName">'.$product['product_name'].'</span><br />
'.($product['product_reference'] ? $this->l('Ref:').' '.$product['product_reference'] : '')
.(($product['product_reference'] AND $product['product_supplier_reference']) ? ' / '.$product['product_supplier_reference'] : '')
.'</a></td>
Put this code at the top of your file :
$product_name = $product['product_name']
$pos = strpos($product_name, ' - ');
if($pos !== false) {
$product_name = substr_replace($product_name, '<br />', $pos, 3);
}
$product_name = str_replace(', ', '<br />', $product_name);
We replace the first ' - ' and each ', ' by a <br /> so each attributes are on a single line.
Then you can use $product_name instead of $product['product_name'] in your code :
<td><a href="index.php?tab=AdminCatalog&id_product='.$product['product_id'].'&updateproduct&token='.$tokenCatalog.'">
<span class="productName">'.$product_name.'</span><br />
'.($product['product_reference'] ? $this->l('Ref:').' '.$product['product_reference'] : '')
.(($product['product_reference'] AND $product['product_supplier_reference']) ? ' / '.$product['product_supplier_reference'] : '')
.'</a></td>
I am new to Opencart, and it's really amazing.
I just want to insert an image in database but I am not able to upload. Here is what I've done.
Template:
<div class="col-sm-10">
<img src="" name="image" id="image" style="width: 26%;height: 100px;" >
<input type="file"
name="photo"
value="<?php echo $photo; ?>"
placeholder="<?php echo $entry_photo; ?>"
id="photo"
onChange="PreviewImages();"/>
<?php if ($error_photo) { ?>
<div class="text-danger"><?php echo $error_photo; ?></div>
<?php } ?>
</div>
Controller:
if (is_uploaded_file($this->request->files['photo']['tmp_name'])) {
$handle = fopen($this->request->files['photo']['tmp_name'], "r");
// If we know there is only a 10 chars PIN per line
// it is better to lower the expected line length
// to lower the memory consumption...
while (($pins = fgetcsv($handle, 50, ",")) !== false) {
$data['photo'][] = $pins; // there is only one PIN per line
}
fclose($handle);
} else {
$data['photo'] = array();
}
Model:
$this->db->query("
INSERT INTO " . DB_PREFIX . "customer
SET customer_group_id = '" . (int)$customer_group_id . "',
store_id = '" . (int)$this->config->get('config_store_id') . "',
firstname = '" . $this->db->escape($data['firstname']) . "',
lastname = '" . $this->db->escape($data['lastname']) . "',
photo = '" . $this->db->escape($data['photo']) . "',
date = '" . $this->db->escape($data['date']) . "',
email = '" . $this->db->escape($data['email']) . "',
telephone = '" . $this->db->escape($data['telephone']) . "',
fax = '" . $this->db->escape($data['fax']) . "',
custom_field = '" . $this->db->escape(isset($data['custom_field']['account']) ? serialize($data['custom_field']['account']) : '') . "',
salt = '" . $this->db->escape($salt = substr(md5(uniqid(rand(), true)), 0, 9)) . "',
password = '" . $this->db->escape(sha1($salt . sha1($salt . sha1($data['password'])))) . "',
newsletter = '" . (isset($data['newsletter']) ? (int)$data['newsletter'] : 0) . "',
ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "',
status = '1',
approved = '" . (int)!$customer_group_info['approval'] . "',
date_added = NOW()
");
$customer_id = $this->db->getLastId();
Opencart 2.0
"I just want to insert an image in db but i am not able to upload. Here is what I've done."-Sruthi
Need to change 3 files
oc2\catalog\view\theme\default\template\account\register.tpl
<div class="form-group required">
<label class="col-sm-2 control-label" for="input-telephone">Upload Image</label>
<div class="col-sm-10">
<button type="button" id="uploadimage" data-loading-text="<?php echo $text_loading; ?>" class="btn btn-default"><i class="fa fa-upload"></i> Upload Image</button>
<input type="hidden" name="custom_field" value="" />
<input type="hidden" name="photo" />
<div id="demo"></div>
</div>
</div>
<script type="text/javascript"><!--
$('button[id^=\'uploadimage\']').on('click', function() {
var node = this;
$('#form-upload').remove();
$('body').prepend('<form enctype="multipart/form-data" id="form-upload" style="display: none;"><input type="file" name="file" /></form>');
$('#form-upload input[name=\'file\']').trigger('click');
timer = setInterval(function() {
if ($('#form-upload input[name=\'file\']').val() != '') {
clearInterval(timer);
$.ajax({
url: 'index.php?route=tool/upload',
type: 'post',
dataType: 'json',
data: new FormData($('#form-upload')[0]),
cache: false,
contentType: false,
processData: false,
beforeSend: function() {
$(node).button('loading');
},
complete: function() {
$(node).button('reset');
},
success: function(json) {
$(node).parent().find('.text-danger').remove();
if (json['error']) {
$(node).parent().find('input').after('<div class="text-danger">' + json['error'] + '</div>');
}
if (json['success']) {
alert(json['success']);
$(node).parent().find('input').attr('value', json['code']);
$(node).parent().find('input[name=photo]').attr('value', json['photo']);
document.getElementById("demo").innerHTML = '<img src="' + json['photo'] +'" width="100px" height="100px">';
}
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
}
}, 500);
});
//--></script>
oc2\catalog\controller\tool\upload.php line 70
From
$json['code'] = $this->model_tool_upload->addUpload($filename, $file);
$json['success'] = $this->language->get('text_upload');
To
$json['code'] = $this->model_tool_upload->addUpload($filename, $file);
$json['success'] = $this->language->get('text_upload');
$json['photo'] = DIR_UPLOAD . $file;
oc2\catalog\model\account\customer.php
$this->db->query("INSERT INTO " . DB_PREFIX . "customer
SET customer_group_id = '" . (int)$customer_group_id . "',
store_id = '" . (int)$this->config->get('config_store_id') . "',
firstname = '" . $this->db->escape($data['firstname']) . "',
lastname = '" . $this->db->escape($data['lastname']) . "',
photo = '" . $this->db->escape($data['photo']) . "',
email = '" . $this->db->escape($data['email']) . "',
telephone = '" . $this->db->escape($data['telephone']) . "',
fax = '" . $this->db->escape($data['fax']) . "',
custom_field = '" . $this->db->escape(isset($data['custom_field']['account']) ? serialize($data['custom_field']['account']) : '') . "',
salt = '" . $this->db->escape($salt = substr(md5(uniqid(rand(), true)), 0, 9)) . "',
password = '" . $this->db->escape(sha1($salt . sha1($salt . sha1($data['password'])))) . "',
newsletter = '" . (isset($data['newsletter']) ? (int)$data['newsletter'] : 0) . "',
ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "',
status = '1',
approved = '" . (int)!$customer_group_info['approval'] . "',
date_added = NOW()");
Ask me if you didn't understand or need something else
You did not mention in which page you are trying to upload but don't forget to add enctype="multipart/form-data" in form in case of upload.
if (is_uploaded_file($this->request->files['photo']['tmp_name'])) {
$handle = fopen($this->request->files['photo']['tmp_name'], "r");
// If we know there is only a 10 chars PIN per line
// it is better to lower the expected line length
// to lower the memory consumption...
while (($pins = fgetcsv($handle, 50, ",")) !== false) {
$data['photo'][] = $pins; // there is only one PIN per line
}
fclose($handle);
} else {
$data['photo'] = array();
}
Please replace above code by followings:
$data['photo'] = '';
$uploads_dir = 'image/data/'; // set you upload path here
if (is_uploaded_file($this->request->files['photo']['tmp_name'])) {
move_uploaded_file($this->request->files['photo']['tmp_name'],$uploads_dir.$this->request->files['photo']['name']);
$data['photo'] = $this->request->files['photo']['name'];
}
Hey anyone can help me with this problem ?
I have this issue with my code, two files:
1 - test.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Documento sin título</title>
<script>
var url = "getagentids.php?param=";
function handleHttpResponse() {
if (http.readyState == 4) {
results = http.responseText.split(",");
document.getElementById('formality').value = results[0];
document.getElementById('fullname').value = results[1];
document.getElementById('sex').value = results[2];
document.getElementById('id').value = results[3];
document.getElementById('joindate').value = results[4];
document.getElementById('jobtitle').value = results[5];
document.getElementById('city').value = results[6];
document.getElementById('typeofsalary').value = results[7];
document.getElementById('contract_type').value = results[8];
}
}
function getagentids() {
var idValue = document.getElementById("email").value;
var myRandom=parseInt(Math.random()*99999999); // cache buster
http.open("GET", url + escape(idValue) + "&rand=" + myRandom, true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
}
function getHTTPObject() {
var xmlhttp;
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp = false;
}
}
return xmlhttp;
}
var http = getHTTPObject();
</script>
</head>
<body>
<form name="schform">
<table bgcolor="#dddddd">
<tbody>
<?php
echo $param;
include '../../../connect.php';
$db =& JFactory::getDBO();
$query = "SELECT email FROM dbemployeekpw";
$db->setQuery($query);
$result = $db->loadObjectList();
$email = $result[0];
echo " <select size='1' name='email' id='email' onChange='getagentids()' required >
<option value=''> Seleccione </option>";
foreach($result as $email)
{
echo "<option value='".$email->email."'>".$email->email."</option>";
}
echo "</select>"
?>
<tr><td>Formality</td><td><input id="formality" type="text" name="formality"></td></tr>
<tr><td>Fullname</td><td><input id="fullname" type="text" name="fullname"></td></tr>
<tr><td>Sex</td><td><input id="sex" type="text" name="sex"></td></tr>
<tr><td>Id</td><td><input id="id" type="text" name="id"></td></tr>
<tr><td>Joindate</td><td><input id="joindate" type="text" name="joindate"></td></tr>
<tr><td>Jobtitle</td><td><input id="jobtitle" type="text" name="jobtitle"></td></tr>
<tr><td>City</td><td><input id="city" type="text" name="city"></td></tr>
<tr><td>Typesalary</td><td><input id="typeofsalary" type="text" name="typeofsalary"></td></tr>
<tr><td>Contract Type</td><td><input id="contract_type" type="text" name="contract_type"> </td></tr>
<tr><td><input size="60" type="reset" value="Clear"></td><td></td>
</tr>
</tbody></table>
</form>
</body>
</html>
and..
2 - getagentids.php
<?php
//$param = $_GET["param"];
include '../../../connect.php';
$db =& JFactory::getDBO();
$query = $db->getQuery(true);
$query = "SELECT * FROM dbemployeekpw WHERE email = 'camilo.uribe#kantarworldpanel.com'";
$db->setQuery($query);
$results = $db->loadObjectList();
foreach ( $results as $result )
{
$formality = $result->formality;
$fullname = $result->fullname;
$sex = $result->sex;
$id = $result->id;
$joindate = $result->joindate;
$jobtitle = $result->jobtitle;
$city = $result->city;
$typeofsalary = $result->typeofsalary;
$contract_type = $result->contract_type;
$textout = $formality.",".$fullname.",".$sex.",".$id.",".$joindate.",".$jobtitle.",".$city.",".$typeofsalary.",".$contract_type;
}
echo $textout;
?>
But ajax dont works, only works if I put this :
$query = "SELECT * FROM dbemployeekpw WHERE email = 'camilo.uribe#kantarworldpanel.com'";
instead this:
$query = "SELECT * FROM dbemployeekpw WHERE email = '".$param."'";
But I need that the code works with second one :(
Anyone can help me with this problem ?
Thanks !!
SOLVED (works like a charm!!):
I change this:
$jinput = JFactory::getApplication()->input;
$param = $jinput->get('param', 'param', 'filter');
instead this:
$param = $_GET["param"];
and I'm still with:
$query = "SELECT * FROM dbemployeekpw WHERE email = '".$param."'";
because this code don't works for me:
$query->select($db->quoteName('*'))
->from($db->quoteName('dbemployeekpw'))
->where($db->quoteName('email') . ' = '. $db->quote($param));
Many Thanks #lodder
Before anything, lets see if the $param variable is correct and gets the value. Add the following which one the form is processed, will display the value. If the result is NULL then you firstly need to ensure you get the correct value. If you do get the correct value, then carry on reading.
Just on a side note, I would recommend looking at the following link rather than using $_GET:
http://docs.joomla.org/Retrieving_request_data_using_JInput
Lets now use up to date coding standards for you database query:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName('*'))
->from($db->quoteName('dbemployeekpw'))
->where($db->quoteName('email') . ' = '. $db->quote($param));
$db->setQuery($query);
$results = $db->loadObjectList();
Hope this helps
Using the doc, I can set my own helper for the layout surrending my field, but I'd like to personalize also some fields given by play.
The main reason is for Twitter Bootstrap 2, where I need to change (in checkbox.scala.html)
#input(field, args:_*) { (id, name, value, htmlArgs) =>
<input type="checkbox" id="#id" name="#name" value="#boxValue" #(if(value == Some(boxValue)) "checked" else "") #toHtmlArgs(htmlArgs.filterKeys(_ == 'value))>
<span>#args.toMap.get('_text)</span>
}
to :
<label class="checkbox">
<input type="checkbox" name="#name" id="#id" value="#boxValue" #(if(value == Some(boxValue)) "checked" else "") #toHtmlArgs(htmlArgs.filterKeys(_ == 'value)) />
#args.toMap.get('_text)
</label>
How can I do that ?
Thanks for your help!
I finally did it like this :
I created a package views.helpers.form, that contains :
bootstrap.scala.html :
#(elements: helper.FieldElements)
<div class="control-group#if(elements.hasErrors) { error}">
<label class="control-label" for="#elements.id">#elements.label(elements.lang)</label>
<div class="controls">
#elements.input
#elements.infos(elements.lang).map { info =>
<span class="help-inline">#info</span>
}
#elements.errors(elements.lang).map { error =>
<span class="help-block">#error</span>
}
</div>
checkbox.scala.html :
#**
* Generate an HTML input checkbox.
*
* Example:
* {{{
* #checkbox(field = myForm("done"))
* }}}
*
* #param field The form field.
* #param args Set of extra HTML attributes ('''id''' and '''label''' are 2 special arguments).
* #param handler The field constructor.
*#
#(field: play.api.data.Field, args: (Symbol,Any)*)(implicit handler: helper.FieldConstructor, lang: play.api.i18n.Lang)
#boxValue = #{ args.toMap.get('value).getOrElse("true") }
#helper.input(field, args:_*) { (id, name, value, htmlArgs) =>
<label class="checkbox">
<input type="checkbox" id="#id" name="#name" value="#boxValue" #(if(value == Some(boxValue)) "checked" else "") #toHtmlArgs(htmlArgs.filterKeys(_ == 'value))>
#args.toMap.get('_text)
</label>
div>
</div>
And in my template, all I have to do is :
#import helper.{FieldConstructor, inputText, inputPassword} #** Import the original helpers *#
#import helpers.form.checkbox #** Import my helpers *#
#implicitField = #{ FieldConstructor(helpers.form.bootstrap.f) }
And voilà! It works!
It will be simpler to just write your own tag with the code you want and use it instead of the provided helper. It will simplify potential issues related to overwritting platform tags.