how to give prompt for yii dependent dropdown once the value is passed from database - yii

I have created a dependent dropdown that shows delivery time for selected area,by default it will show aprompt which i have given at the view page but when i choose an area it directly displays the values with first value as selected ,how can i give a prompt instead the first value get selected .here my action
public function actionGetdeliveryforarea()
{
$data=Areatimeslot::model()->findAll('area_id=:area_id',
array(':area_id'=>(int) $_POST['area_id']));
$data=CHtml::listData($data,'deliverytime','timeName');
foreach($data as $value=>$deliverytime)
{
echo CHtml::tag('option',
array('value'=>$value,),CHtml::encode($deliverytime),true);
}
}

Update your action as follows
public function actionGetdeliveryforarea()
{
$data=Areatimeslot::model()->findAll('area_id=:area_id',
array(':area_id'=>(int) $_POST['area_id']));
$data=CHtml::listData($data,'deliverytime','timeName');
echo CHtml::tag('option',
array('value'=>'',),CHtml::encode("Select Value"),true);
foreach($data as $value=>$deliverytime)
{
echo CHtml::tag('option',
array('value'=>$value,),CHtml::encode($deliverytime),true);
}
}

Related

What are the possible ways of validating whether all element displayed or not

When I hover the mouse on button, then many options are displayed. Now I want to validate that all the options are displayed or not at single time.
static content = {
timeRangeContainer { $("div.filter-list")[0] }
timeRangeFilterOptions { timeRangeContainer.find ("div.filter-drop li")}
}
def hovermouse(){
interact{
moveToElement(timeRangeFilterButton)
}
def optionDisplayed(){
timeRangeFilterOptions[0].isDisplayed()
}
}
In the above example, I can check only one element whether it displayed or not , But I want to check all the options are displayed or not at single line of code such as (timeRangeFilterOptions.isDisplayed()). Is it possible ?
One way to do it would be:
boolean optionsDisplayed(){
timeRangeFilterOptions*.displayed.every()
}

Show to be deleted items in popup window

I am using Odoo 10e. I want a simple functionality that whenever i wanted to delete one or more then one item from a list view or from a specific list view only. I want to show all of the items which are selected for deleted to show their name in popup window so that user can have a quick review what's he is going to delete. I know user can see details in list view but i want to give a glimpse to user in shape of model window that this is going to be deleted. Are you sure to delete ?
If user click Confirm then normal delete case should work.
As far i research and worked on it, i have idea that it should be something regarding overriding the do_delete method in the list_view.js in the web module. But i didn't know much about javascript overriding for Odoo.
This is an example how I do it.
I called the name_get for your model and records ids, this names list, I change the text of confirming message with the information of ids selected.
do_delete: function (ids) {
new Model(this.model)
.call('name_get', [ids, this.dataset.get_context()]).done(function (names) {
var text = _t("Do you really want to remove these records?") + ' '+ names.join(' \n')
if (!(ids.length && confirm(text))) {
return;
}
var self = this;
return $.when(this.dataset.unlink(ids)).done(function () {
_(ids).each(function (id) {
self.records.remove(self.records.get(id));
});
// Hide the table if there is no more record in the dataset
if (self.display_nocontent_helper()) {
self.no_result();
} else {
if (self.records.length && self.current_min === 1) {
// Reload the list view if we delete all the records of the first page
self.reload();
} else if (self.records.length && self.dataset.size() > 0) {
// Load previous page if the current one is empty
self.pager.previous();
}
// Reload the list view if we are not on the last page
if (self.current_min + self._limit - 1 < self.dataset.size()) {
self.reload();
}
}
self.update_pager(self.dataset);
self.compute_aggregates();
});
});;
},

Not Updating The Image Doesn't Update The Record

The problem is if I want to update the other fields and not the image. It passes the validation and doesn't update any of the fields.
But if I update the image and other fields it updates. Or if i update the image it updates.
View:
<?php echo $form->labelEx($model,'pimg'); ?>
<?php echo $form->fileField($model, 'pimg',array('id'=>'imgInput',)); ?>
<?php echo $form->error($model,'pimg'); ?>
Controller:
public function actionEdit($id)
{
$model=$this->loadModel($id);
if(isset($_POST['Product']))
{
$model->pimg=CUploadedFile::getInstance($model,'pimg');
$fileName=$model->pimg;
$model->attributes=$_POST['Product'];
if($model->save())
$model->pimg->saveAs('images/'.$fileName);
$this->redirect(array('display','id'=>$model->productid));
}
$this->render('edit',array('model'=>$model,));
}
Model rules:
array('name, category, model, brand, description, price', 'required'),
array('pimg', 'file','types'=>'jpg','on'=>'create', 'allowEmpty'=>false),
array('pimg', 'file','types'=>'jpg','on'=>'update', 'allowEmpty'=>true),
I think the problem is with the controller. I keep getting the error:
Fatal error: Call to a member function saveAs() on a non-object in D:\wamp\www\testfolder\protected\controllers\ProductController.php on line 147
line 147: $model->pimg->saveAs('images/'.$fileName);
Image appears but then image name from db doesn't appear next to the choose file button renders stating no file chosen.
Note that I am new to Yii, and am stuck with this.
The problem is in your actionEdit i.e here
$model->pimg=CUploadedFile::getInstance($model,'pimg');
$fileName=$model->pimg;
$model->attributes=$_POST['Product'];
if($model->save())
$model->pimg->saveAs('images/'.$fileName);
here you should check if the image has been uploaded or not. what happens is that yii is unable to execute this line $model->pimg->saveAs('images/'.$fileName); as no image has been uploaded. so you need to wrap it inside a condition i.e
if(!empty($model->pimg))
{
$model->pimg->saveAs('images/'.$fileName);
}
so your final code should be something like this
$model->attributes=$_POST['Product'];
$model->pimg=CUploadedFile::getInstance($model,'pimg');
if(!empty($model->pimg))
{
$fileName=$model->pimg->name;
$model->pimg->saveAs('images/'.$fileName);
}
if($model->save())
//render here
Update 1
If you want that on update null should not be stored in your database then you can do this
$model=$this->loadModel($id);
$prevImage=$model->pimg; //add this line
and then where you are using this
if(!empty($model->pimg))
{
$model->pimg->saveAs('images/'.$fileName);
}
else{
$model->pimg=$prevIMage;
}
add this else code

How To Count Views On Click Of A Button Or Web Page Is There Any Extension

I am a newbie interested to know are there any extension to count views on click of a button as to know no. of registered users or visiters to web page to know the view count on click of a image is there any extension.
Plz let me know if any
thanx :)
I think , there is no need of any extension. Make a Ajax call on click button or image you are interested.
Improved:
I supposed you have Site as controller and index as action. then, please keep this code on views/site/index.php .
Yii::app()->clientScript->registerScript('logo_as_image_script', '$(document).ready(function() {
$("#logo_as_image").click(function() {
$.post("'.Yii::app()->createAbsoluteUrl('site/index').'",
{
clicked: "1"
},
function(data, status) {
alert("Data: " + data + "\nStatus: " + status);
});
});
});');
Yii::app()->clientScript->registerCoreScript('jquery');
echo CHtml::image(Yii::app()->baseUrl . '/images/logo.png', 'Logo as Image', array('id' => 'logo_as_image'));
And, keep this code on SiteController.php .
public function actionIndex()
{
// keep record of data ; do more filtering ; other manupulation
if(isset($_POST['clicked'])){
$nextCount = Yii::app()->user->getState('clickCount')+1;
Yii::app()->user->setState('clickCount',$nextCount );
echo $nextCount;
Yii::app()->end();
}
#other codes here.
$this->render('index');
}
Lets assume that you want to store how many registered users have accessed the page at :
www.something.com/something/someaction
then visit the controller and add the code like so :
public function actionSomeAction()
{
$model = new CountDbModel();
if(!Yii::app()->user->isGuest){
$model->page = 'This page name here.';
$model->user_id = Yii::app()->user->id;
$model->count = #Add the value here.
#You other code here....
$this->render('whateverView',array('model'=>$blah));
}
}
I hope it helped.

Confirm Message on DropDown Select Change

I need to show a Confirm message when the value Hiring is selected in the dropdown. How can I do that?
if (Status.SelectedValue == "HIRING")
{
Status.Attributes.Add("onChange", "javascript:return DisplayConfirmation();");
}
I have the function DisplayConfirmation in aspx page. This does not work.
Alter the DisplayConfirmation() javascript function to include a parameter for the selected value, and handle the logic inside the function.
In the Code behind, replace your code with this:
Status.Attributes.Add("OnChange", string.Format("DisplayConfirmation('{0}');", Status.SelectedValue));
So, you can change your javascript to be
function DisplayConfirmation(Status) {
if(Status == "HIRING")
{
if (confirm('Are you sure you want to do this?')) { __doPostback('Status', ''); }
}}