Commits

Bogdan Savluk committed ad91a7f

Added link property for PhotoI18n

Comments (0)

Files changed (10)

GalleryBehavior.php

     public $name;
     /** @var boolean does images in gallery need descriptions */
     public $description;
+    /** @var boolean does images in gallery need links */
+    public $link;
+
     private $_gallery;
 
     /** Will create new gallery after save if no associated gallery exists */
                 $gallery = new Gallery();
                 $gallery->name = $this->name;
                 $gallery->description = $this->description;
+                $gallery->link = $this->link;
                 $gallery->versions = $this->versions;
                 $gallery->save();
 
 
         $gallery->name = $this->name;
         $gallery->description = $this->description;
+        $gallery->link = $this->link;
         $gallery->versions = $this->versions;
         $gallery->save();
 

GalleryController.php

                 $i18ns[$lang] = array(
                     'name' => (string)$i18nModels[$lang]->name,
                     'description' => (string)$i18nModels[$lang]->description,
+                    'link' => (string)$i18nModels[$lang]->link,
                 );
             }
             echo CJSON::encode(
                             $i18nModels[$lang]->name = $attributes[$lang]['name'];
                         if (isset($attributes[$lang]['description']))
                             $i18nModels[$lang]->description = $attributes[$lang]['description'];
+                        if (isset($attributes[$lang]['link']))
+                            $i18nModels[$lang]->link = $attributes[$lang]['link'];
                         $i18nModels[$lang]->save();
                     }
                 }
                     $i18ns[$lang] = array(
                         'name' => (string)$model->i18ns[$lang]->name,
                         'description' => (string)$model->i18ns[$lang]->description,
+                        'link' => (string)$model->i18ns[$lang]->link,
                     );
                 }
                 $resp[] = array(

GalleryManager.php

                 $i18ns[$lang] = array(
                     'name' => (string)$photo->i18ns[$lang]->name,
                     'description' => (string)$photo->i18ns[$lang]->description,
+                    'link' => (string)$photo->i18ns[$lang]->link,
                 );
             }
             $photos[] = array(
             'langs' => Yii::app()->params['languages'],
             'hasName' => $this->gallery->name ? true : false,
             'hasDesc' => $this->gallery->description ? true : false,
+            'hasLink' => $this->gallery->link ? true : false,
             'uploadUrl' => Yii::app()->createUrl($this->controllerRoute . '/ajaxUpload', array('gallery_id' => $this->gallery->id)),
             'deleteUrl' => Yii::app()->createUrl($this->controllerRoute . '/delete'),
             'updateUrl' => Yii::app()->createUrl($this->controllerRoute . '/changeData'),
             'arrangeUrl' => Yii::app()->createUrl($this->controllerRoute . '/order'),
             'nameLabel' => Yii::t('galleryManager.main', 'Name'),
             'descriptionLabel' => Yii::t('galleryManager.main', 'Description'),
+            'linkLabel' => Yii::t('galleryManager.main', 'Link'),
             'photos' => $photos,
         ));
         $src = "$('#{$this->id}').galleryManager({$opts});";

assets/jquery.galleryManager.js

             langs:['ru', 'en'],
             nameLabel:'Name',
             descriptionLabel:'Description',
+            linkLabel:'Link',
 
             hasName:true,
             hasDesc:true,
+            hasLink:true,
 
             uploadUrl:'',
             deleteUrl:'',
         var $editorModal = $('.editor-modal', $gallery);
 
 
-        function photoEditorTemplate(id, src, name, description, lang) {
+        function photoEditorTemplate(id, src, name, description, link, lang) {
             return '<div class="photo-editor">' +
                 '<div class="preview"><img src="' + src + '" alt=""/></div>' +
                 '<div>' +
                     ? '<label for="photo_name_' + id + '_' + lang + '">' + opts.nameLabel + ':</label>' +
                     '<input type="text" name="photo[' + id + '][' + lang + '][name]" class="input-xlarge" value="' + name + '" id="photo_name_' + id + '_' + lang + '"/>'
                     : '') +
+                (opts.hasLink
+                    ? '<label for="photo_link_' + id + '_' + lang + '">' + opts.linkLabel + ':</label>' +
+                    '<input type="text" name="photo[' + id + '][' + lang + '][link]" class="input-xlarge" value="' + link + '" id="photo_link_' + id + '_' + lang + '"/>'
+                    : '') +
                 (opts.hasDesc
                     ? '<label for="photo_description_' + id + '_' + lang + '">' + opts.descriptionLabel + ':</label>' +
                     '<textarea name="photo[' + id + '][' + lang + '][description]" rows="3" cols="40" class="input-xlarge" id="photo_description_' + id + '_' + lang + '">' + description + '</textarea>'
             var photoData = photo.data('data');
             for (var i in opts.langs) {
                 var lang = opts.langs[i];
-                $('#' + opts.wId + '_editor_tab_' + lang + ' .form', $editorModal).html(photoEditorTemplate(id, photoData['preview'], photoData['i18ns'][lang]['name'], photoData['i18ns'][lang]['description'], lang))
+                $('#' + opts.wId + '_editor_tab_' + lang + ' .form', $editorModal).html(photoEditorTemplate(id, photoData['preview'], photoData['i18ns'][lang]['name'], photoData['i18ns'][lang]['description'], photoData['i18ns'][lang]['link'], lang))
             }
             $editorModal.modal('show');
             return false;
                             if (opts.hasName || opts.hasDesc){
                                 for (var i in opts.langs) {
                                     var lang = opts.langs[i];
-                                    $('#' + opts.wId + '_editor_tab_' + lang + ' .form', $editorModal).append(photoEditorTemplate(resp['id'], resp['preview'], resp['i18ns'][lang]['name'], resp['i18ns'][lang]['description'], lang))
+                                    $('#' + opts.wId + '_editor_tab_' + lang + ' .form', $editorModal).append(photoEditorTemplate(resp['id'], resp['preview'], resp['i18ns'][lang]['name'], resp['i18ns'][lang]['description'],resp['i18ns'][lang]['link'], lang))
                                 }
                             }
                         }
                         if (opts.hasName || opts.hasDesc){
                             for (var i in opts.langs) {
                                 var lang = opts.langs[i];
-                                $('#' + opts.wId + '_editor_tab_' + lang + ' .form', $editorModal).append(photoEditorTemplate(resp['id'], resp['preview'], resp['i18ns'][lang]['name'], resp['i18ns'][lang]['description'], lang))
+                                $('#' + opts.wId + '_editor_tab_' + lang + ' .form', $editorModal).append(photoEditorTemplate(resp['id'], resp['preview'], resp['i18ns'][lang]['name'], resp['i18ns'][lang]['description'],  resp['i18ns'][lang]['link'], lang))
                             }
                         }
                         if (opts.hasName || opts.hasDesc) $editorModal.modal('show');
                 var photoData = photo.data('data');
                 for (var i in opts.langs) {
                     var lang = opts.langs[i];
-                    $('#' + opts.wId + '_editor_tab_' + lang + ' .form', $editorModal).append(photoEditorTemplate(id, photoData['preview'], photoData['i18ns'][lang]['name'], photoData['i18ns'][lang]['description'], lang))
+                    $('#' + opts.wId + '_editor_tab_' + lang + ' .form', $editorModal).append(photoEditorTemplate(id, photoData['preview'], photoData['i18ns'][lang]['name'], photoData['i18ns'][lang]['description'], photoData['i18ns'][lang]['link'], lang))
                 }
             });
             if (cc > 0)$editorModal.modal('show');

assets/jquery.galleryManager.min.js

-(function(a){function b(b,c){function i(a,b,c,e,f){return'<div class="photo-editor"><div class="preview"><img src="'+b+'" alt=""/></div>'+"<div>"+(d.hasName?'<label for="photo_name_'+a+"_"+f+'">'+d.nameLabel+":</label>"+'<input type="text" name="photo['+a+"]["+f+'][name]" class="input-xlarge" value="'+c+'" id="photo_name_'+a+"_"+f+'"/>':"")+(d.hasDesc?'<label for="photo_description_'+a+"_"+f+'">'+d.descriptionLabel+":</label>"+'<textarea name="photo['+a+"]["+f+'][description]" rows="3" cols="40" class="input-xlarge" id="photo_description_'+a+"_"+f+'">'+e+"</textarea>":"")+"</div>"+"</div>"}function j(a,b,c,e,f){var g='<div id="'+d.wId+"-"+a+'" class="photo">'+'<div class="image-preview"><img src="'+b+'"/></div><div class="caption">';return d.hasName&&(g+="<h5>"+c+"</h5>"),d.hasDesc&&(g+="<p>"+e+"</p>"),g+='</div><input type="hidden" name="order['+a+']" value="'+f+'"/><div class="actions">'+(d.hasName||d.hasDesc?'<span data-photo-id="'+a+'" class="editPhoto btn btn-primary"><i class="icon-edit icon-white"></i></span> ':"")+'<span data-photo-id="'+a+'" class="deletePhoto btn btn-danger"><i class="icon-remove icon-white"></i></span>'+'</div><input type="checkbox" class="photo-select"/></div>',g}function k(b){b.preventDefault();var c=a(this).data("photo-id");return a.ajax({type:"POST",url:d.deleteUrl,data:"id="+c,success:function(b){b=="OK"?a("#"+d.wId+"-"+c).remove():alert(b)}}),!1}function l(b){b.preventDefault();var c=a(this).data("photo-id"),e=a(this).parents(".photo"),f=e.data("data");for(var g in d.langs){var j=d.langs[g];a("#"+d.wId+"_editor_tab_"+j+" .form",h).html(i(c,f.preview,f.i18ns[j].name,f.i18ns[j].description,j))}return h.modal("show"),!1}function m(){var b=a(".photo.selected",f).length;a(".select_all",e).prop("checked",a(".photo",f).length==b),b==0?a(".edit_selected, .remove_selected",e).addClass("disabled"):a(".edit_selected, .remove_selected",e).removeClass("disabled")}function n(){var b=a(this);b.is(":checked")?b.parent().addClass("selected"):b.parent().removeClass("selected"),m()}function o(b){a(".deletePhoto",b).click(k),a(".editPhoto",b).click(l),a(".photo-select",b).change(n)}this.defaults={lang:"ru",langs:["ru","en"],nameLabel:"Name",descriptionLabel:"Description",hasName:!0,hasDesc:!0,uploadUrl:"",deleteUrl:"",updateUrl:"",arrangeUrl:"",photos:[]};var d=a.extend({},this.defaults,c),e=a(b);d.wId=e.attr("id");var f=a(".sorter",e),g=a(".images",f),h=a(".editor-modal",e);a(".images",f).sortable().disableSelection().bind("sortstop",function(){a.post(d.arrangeUrl,a("input",f).serialize()+"&ajax=true",function(){},"json")}),typeof window.FormData=="function"?a(".afile",e).attr("multiple","true").on("change",function(b){b.preventDefault();var c=this.files.length,e=0;a(".form",h).html("");for(var f=0;f<c;f++){var k=new FormData;k.append(this.name,this.files[f]);var l=new XMLHttpRequest;l.open("POST",d.uploadUrl,!0),l.onload=function(){e++;if(this.status==200){var b=JSON.parse(this.response),f=a(j(b.id,b.preview,b.i18ns[d.lang].name,b.i18ns[d.lang].description,b.rank)).data("data",b);o(f),g.append(f);if(d.hasName||d.hasDesc)for(var k in d.langs){var l=d.langs[k];a("#"+d.wId+"_editor_tab_"+l+" .form",h).append(i(b.id,b.preview,b.i18ns[l].name,b.i18ns[l].description,l))}}e===c&&(d.hasName||d.hasDesc)&&h.modal("show")},l.send(k)}}):a(".afile",e).on("change",function(b){b.preventDefault(),a(".form",h).html(""),a.ajax(d.uploadUrl,{files:a(this),iframe:!0,dataType:"json"}).done(function(b){var c=a(j(b.id,b.preview,b.i18ns[d.lang].name,b.i18ns[d.lang].description,b.rank)).data("data",b);o(c),g.append(c);if(d.hasName||d.hasDesc)for(var e in d.langs){var f=d.langs[e];a("#"+d.wId+"_editor_tab_"+f+" .form",h).append(i(b.id,b.preview,b.i18ns[f].name,b.i18ns[f].description,f))}(d.hasName||d.hasDesc)&&h.modal("show")})}),a(".save-changes",h).click(function(b){b.preventDefault(),a.post(d.updateUrl,a(".form input, .form textarea",h).serialize()+"&ajax=true",function(b){var c=b.length;for(var g=0;g<c;g++){var i=b[g],j=a("#"+d.wId+"-"+i.id);j.data("data",i),a("img",j).attr("src",i.src),d.hasName&&a(".caption h5",j).text(i.i18ns[d.lang].name),d.hasDesc&&a(".caption p",j).text(i.i18ns[d.lang].description)}h.modal("hide"),a(".photo.selected",f).each(function(){a(".photo-select",this).prop("checked",!1)}).removeClass("selected"),a(".select_all",e).prop("checked",!1),m()},"json")}),a(".edit_selected",e).click(function(b){b.preventDefault();var c=0,e=a(".form",h).html("");return a(".photo.selected",f).each(function(){c++;var b=a(this),e=b.attr("id").substr((d.wId+"-").length),f=b.data("data");for(var g in d.langs){var j=d.langs[g];a("#"+d.wId+"_editor_tab_"+j+" .form",h).append(i(e,f.preview,f.i18ns[j].name,f.i18ns[j].description,j))}}),c>0&&h.modal("show"),!1}),a(".remove_selected",e).click(function(b){b.preventDefault(),a(".photo.selected",f).each(function(){var b=a(this).attr("id").substr((d.wId+"-").length);a.ajax({type:"POST",url:d.deleteUrl,data:"id="+b,success:function(c){c=="OK"?a("#"+d.wId+"-"+b).remove():alert(c),m()}})})}),a(".select_all",e).change(function(){a(this).prop("checked")?a(".photo",f).each(function(){a(".photo-select",this).prop("checked",!0)}).addClass("selected"):a(".photo.selected",f).each(function(){a(".photo-select",this).prop("checked",!1)}).removeClass("selected"),m()});for(var p in d.photos){var q=d.photos[p],r=a(j(q.id,q.preview,q.i18ns[d.lang].name,q.i18ns[d.lang].description,q.rank)).data("data",q);o(r),g.append(r)}}a.fn.galleryManager=function(a){this.length&&this.each(function(){b(this,a)})}})(jQuery);
+(function(a){function b(b,c){function i(a,b,c,e,f,g){return'<div class="photo-editor"><div class="preview"><img src="'+b+'" alt=""/></div>'+"<div>"+(d.hasName?'<label for="photo_name_'+a+"_"+g+'">'+d.nameLabel+":</label>"+'<input type="text" name="photo['+a+"]["+g+'][name]" class="input-xlarge" value="'+c+'" id="photo_name_'+a+"_"+g+'"/>':"")+(d.hasLink?'<label for="photo_link_'+a+"_"+g+'">'+d.linkLabel+":</label>"+'<input type="text" name="photo['+a+"]["+g+'][link]" class="input-xlarge" value="'+f+'" id="photo_link_'+a+"_"+g+'"/>':"")+(d.hasDesc?'<label for="photo_description_'+a+"_"+g+'">'+d.descriptionLabel+":</label>"+'<textarea name="photo['+a+"]["+g+'][description]" rows="3" cols="40" class="input-xlarge" id="photo_description_'+a+"_"+g+'">'+e+"</textarea>":"")+"</div>"+"</div>"}function j(a,b,c,e,f){var g='<div id="'+d.wId+"-"+a+'" class="photo">'+'<div class="image-preview"><img src="'+b+'"/></div><div class="caption">';return d.hasName&&(g+="<h5>"+c+"</h5>"),d.hasDesc&&(g+="<p>"+e+"</p>"),g+='</div><input type="hidden" name="order['+a+']" value="'+f+'"/><div class="actions">'+(d.hasName||d.hasDesc?'<span data-photo-id="'+a+'" class="editPhoto btn btn-primary"><i class="icon-edit icon-white"></i></span> ':"")+'<span data-photo-id="'+a+'" class="deletePhoto btn btn-danger"><i class="icon-remove icon-white"></i></span>'+'</div><input type="checkbox" class="photo-select"/></div>',g}function k(b){b.preventDefault();var c=a(this).data("photo-id");return a.ajax({type:"POST",url:d.deleteUrl,data:"id="+c,success:function(b){b=="OK"?a("#"+d.wId+"-"+c).remove():alert(b)}}),!1}function l(b){b.preventDefault();var c=a(this).data("photo-id"),e=a(this).parents(".photo"),f=e.data("data");for(var g in d.langs){var j=d.langs[g];a("#"+d.wId+"_editor_tab_"+j+" .form",h).html(i(c,f.preview,f.i18ns[j].name,f.i18ns[j].description,f.i18ns[j].link,j))}return h.modal("show"),!1}function m(){var b=a(".photo.selected",f).length;a(".select_all",e).prop("checked",a(".photo",f).length==b),b==0?a(".edit_selected, .remove_selected",e).addClass("disabled"):a(".edit_selected, .remove_selected",e).removeClass("disabled")}function n(){var b=a(this);b.is(":checked")?b.parent().addClass("selected"):b.parent().removeClass("selected"),m()}function o(b){a(".deletePhoto",b).click(k),a(".editPhoto",b).click(l),a(".photo-select",b).change(n)}this.defaults={lang:"ru",langs:["ru","en"],nameLabel:"Name",descriptionLabel:"Description",linkLabel:"Link",hasName:!0,hasDesc:!0,hasLink:!0,uploadUrl:"",deleteUrl:"",updateUrl:"",arrangeUrl:"",photos:[]};var d=a.extend({},this.defaults,c),e=a(b);d.wId=e.attr("id");var f=a(".sorter",e),g=a(".images",f),h=a(".editor-modal",e);a(".images",f).sortable().disableSelection().bind("sortstop",function(){a.post(d.arrangeUrl,a("input",f).serialize()+"&ajax=true",function(){},"json")}),typeof window.FormData=="function"?a(".afile",e).attr("multiple","true").on("change",function(b){b.preventDefault();var c=this.files.length,e=0;a(".form",h).html("");for(var f=0;f<c;f++){var k=new FormData;k.append(this.name,this.files[f]);var l=new XMLHttpRequest;l.open("POST",d.uploadUrl,!0),l.onload=function(){e++;if(this.status==200){var b=JSON.parse(this.response),f=a(j(b.id,b.preview,b.i18ns[d.lang].name,b.i18ns[d.lang].description,b.rank)).data("data",b);o(f),g.append(f);if(d.hasName||d.hasDesc)for(var k in d.langs){var l=d.langs[k];a("#"+d.wId+"_editor_tab_"+l+" .form",h).append(i(b.id,b.preview,b.i18ns[l].name,b.i18ns[l].description,b.i18ns[l].link,l))}}e===c&&(d.hasName||d.hasDesc)&&h.modal("show")},l.send(k)}}):a(".afile",e).on("change",function(b){b.preventDefault(),a(".form",h).html(""),a.ajax(d.uploadUrl,{files:a(this),iframe:!0,dataType:"json"}).done(function(b){var c=a(j(b.id,b.preview,b.i18ns[d.lang].name,b.i18ns[d.lang].description,b.rank)).data("data",b);o(c),g.append(c);if(d.hasName||d.hasDesc)for(var e in d.langs){var f=d.langs[e];a("#"+d.wId+"_editor_tab_"+f+" .form",h).append(i(b.id,b.preview,b.i18ns[f].name,b.i18ns[f].description,b.i18ns[f].link,f))}(d.hasName||d.hasDesc)&&h.modal("show")})}),a(".save-changes",h).click(function(b){b.preventDefault(),a.post(d.updateUrl,a(".form input, .form textarea",h).serialize()+"&ajax=true",function(b){var c=b.length;for(var g=0;g<c;g++){var i=b[g],j=a("#"+d.wId+"-"+i.id);j.data("data",i),a("img",j).attr("src",i.src),d.hasName&&a(".caption h5",j).text(i.i18ns[d.lang].name),d.hasDesc&&a(".caption p",j).text(i.i18ns[d.lang].description)}h.modal("hide"),a(".photo.selected",f).each(function(){a(".photo-select",this).prop("checked",!1)}).removeClass("selected"),a(".select_all",e).prop("checked",!1),m()},"json")}),a(".edit_selected",e).click(function(b){b.preventDefault();var c=0,e=a(".form",h).html("");return a(".photo.selected",f).each(function(){c++;var b=a(this),e=b.attr("id").substr((d.wId+"-").length),f=b.data("data");for(var g in d.langs){var j=d.langs[g];a("#"+d.wId+"_editor_tab_"+j+" .form",h).append(i(e,f.preview,f.i18ns[j].name,f.i18ns[j].description,f.i18ns[j].link,j))}}),c>0&&h.modal("show"),!1}),a(".remove_selected",e).click(function(b){b.preventDefault(),a(".photo.selected",f).each(function(){var b=a(this).attr("id").substr((d.wId+"-").length);a.ajax({type:"POST",url:d.deleteUrl,data:"id="+b,success:function(c){c=="OK"?a("#"+d.wId+"-"+b).remove():alert(c),m()}})})}),a(".select_all",e).change(function(){a(this).prop("checked")?a(".photo",f).each(function(){a(".photo-select",this).prop("checked",!0)}).addClass("selected"):a(".photo.selected",f).each(function(){a(".photo-select",this).prop("checked",!1)}).removeClass("selected"),m()});for(var p in d.photos){var q=d.photos[p],r=a(j(q.id,q.preview,q.i18ns[d.lang].name,q.i18ns[d.lang].description,q.rank)).data("data",q);o(r),g.append(r)}}a.fn.galleryManager=function(a){this.length&&this.each(function(){b(this,a)})}})(jQuery);

messages/en/main.php

     'Description' => '',
     'Edit information' => '',
     'Edit selected' => '',
+    'Link' => '',
     'Name' => '',
     'Remove selected' => '',
     'Save changes' => '',

messages/ru/main.php

  */
 return array(
     'Description' => 'Описание',
+    'Link' => 'Ссылка',
     'Name' => 'Название',
     'Add images…' => 'Добавить картинки…',
     'Close' => 'Закрыть',

messages/uk/main.php

  */
 return array(
     'Description' => 'Опис',
+    'Link' => 'Ссилка',
     'Name' => 'Назва',
     'Add images…' => 'Додати зображення',
     'Close' => 'Закрити',

models/Gallery.php

  * @property string $versions_data
  * @property integer $name
  * @property integer $description
+ * @property integer $link
  *
  * The followings are the available model relations:
  * @property GalleryPhoto[] $galleryPhotos
         // NOTE: you should only define rules for those attributes that
         // will receive user inputs.
         return array(
-            array('name, description', 'safe'),
+            array('name, description. link', 'safe'),
             // The following rule is used by search().
             // Please remove those attributes that should not be searched.
             array('id, versions_data, name, description', 'safe', 'on' => 'search'),
             'versions_data' => 'Versions Data',
             'name' => 'Name',
             'description' => 'Description',
+            'link' => 'Link',
         );
     }
 

models/GalleryPhotoI18n.php

  * @property string $lang
  * @property string $name
  * @property string $description
+ * @property string $link
  *
  * The followings are the available model relations:
  * @property GalleryPhoto $galleryPhoto
         // NOTE: you should only define rules for those attributes that
         // will receive user inputs.
         return array(
-            array('name', 'length', 'max' => 512),
+            array('name, link', 'length', 'max' => 512),
             array('description', 'safe'),
             // The following rule is used by search().
             // Please remove those attributes that should not be searched.
             'lang' => 'Lang',
             'name' => 'Name',
             'description' => 'Description',
+            'link' => 'Link',
         );
     }
 
         $criteria->compare('id', $this->id);
         $criteria->compare('lang', $this->lang, true);
         $criteria->compare('name', $this->name, true);
+        $criteria->compare('link', $this->link, true);
         $criteria->compare('description', $this->description, true);
 
         return new CActiveDataProvider($this, array(
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.